Search code examples
phparraysstring-concatenation

Array dumps in 5.6 but not PHP 5.5.9


Trying:

var_dump(Map::map);

In PHP 5.5.9 this gives me Parse error: syntax error, unexpected '.', expecting ']' in map.php on line 14 (that is the first concatenation mark in the array declaration below)

In PHP 5.6 it dumps the array without any warnings or notices.

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'
        ]
      ]
    ]
  ];
}

Solution

  • It is because constant arrays were introduced in PHP 5.6. In 5.5~ it will result in a parse error.

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