2017-03-24 21 views
1

尝试:阵列转储在5.6,但不是PHP 5.5.9

var_dump(Map::map); 

在PHP 5.5.9这给了我 解析错误:语法错误,意想不到的,希望 ']' 在map.php ''上线14(即在下面的数组声明第一个串联标记)

在PHP 5.6它转储没有任何警告或通知该阵列。

class Map 
{  
const map = [ 
'admin'    => [ 
    ''    => __DIR__ . 'somefile.php'], 
    'resa'    => __DIR__ . 'somefile.php', 
    'galleri'   => __DIR__ . 'somefile.php', 
    'kategori'   => __DIR__ . 'somefile.php', 
    ''    => [ 
    ''    => __DIR__ . 'somefile.php', 
'katalog'   => __DIR__ . 'somefile.php', 
'resan'    => __DIR__ . 'somefile.php', 
'bussresor'   => __DIR__ . 'somefile.php', 
'kontakt'   => __DIR__ . 'somefile.php'], 
    'ajax'    => __DIR__ . 'somefile.php', 
    'test'    => [ 
    ''    => __DIR__ . 'somefile.php', 
    'test1sub'   => __DIR__ . 'somefile.php', 
    'test2'    => [ 
     ''     => __DIR__ . 'somefile.php', 
     'test2sub'    => __DIR__ . 'somefile.php', 
     'test3'     => [ 
      ''     => __DIR__ . 'somefile.php', 
      'test3sub'    => __DIR__ . 'somefile.php' 
     ] 
     ] 
    ] 
    ]; 
} 
+0

http://php.net/manual/en/migration56.new-features.php#migration56.new-features.const-scalar-exprs –

回答

1

这是因为在PHP 5.6中引入了常量数组。在5.5〜这将导致解析错误。

http://php.net/manual/en/migration56.new-features.php

+0

但它给我同样的错误设置阵列公共静态$地图 所以不设置它唯一的公立,创建一个新的类实例,并用$ MAP-调用它>地图 –

+0

好,但设置了构造的阵列做的工作。 我想这可能是恒定的东西,但并没有意识到任何直接财产申报显然是设置在阵列中相同的上下文。谢谢! –

+0

@HåkanKA如果这个答案是在您看来正确,你可以用“大关”接受它,所以这个问题可以关闭。 – Robert