Missing the fundamentals of arrays in PHP -


can 1 explain why doesn't work:

private static $bundles = array(     'page-builder' => array(         'freya\\bundle\\pagebuilder' => self::$basedir . '/freya-bundle-pagebuilder/freya/bundle/pagebuilder'     ); ); 

self::$basedir __dir__. thought @ run time php evaluate , save out path/to/some/dir/freya- ....

the exact error is:

parse error: syntax error, unexpected '$basedir' (t_variable), expecting identifier (t_string) or class (t_class) in /vagrant/local-dev/content/mu-plugins/freya-mu/bundles/bundleloader.php on line 51

line 51, is: 'freya\\bundle\\pagebuilder' => self::$basedir . '/freya-bundle-pagebuilder/freya/bundle/pagebuilder'

so ... missing , whats proper way this?

php version: 5.5

php not allow this. php properties may initialized constant values, constant values available @ compile time. manual:

this declaration may include initialization, initialization must constant value--that is, must able evaluated @ compile time , must not depend on run-time information in order evaluated.

whatever value static property $basedir holds not available until class definition executed (i.e. runtime).

you can around degree using class constant:

class aclass {     const my_constant = 42;      protected $property = self::my_constant; } 

class constants evaluated @ compile time, need do. note cannot other manipulations (e.g. initialize $property self::my_constant * 3)

i suggest leaving self::$basedir out of property, , either inject in during construction or whenever property being used.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -