phundament / app

Dockerized Yii2 web application base
http://phundament.com
Other
310 stars 129 forks source link

Errors from __DIR__ in class variable initialization #196

Closed sbrendtro closed 8 years ago

sbrendtro commented 8 years ago

There were a number of recent updates that are causing the error:

PHP Parse error: syntax error, unexpected '.', expecting ',' or ';' in {some file}

For example, src/assets/AppAsset.php, line 20:

class AppAsset extends AssetBundle
{
    public $sourcePath = __DIR__.'/web';

In this context, __DIR__ is not a constant value, and class variable initialization must be done with a constant value. (See http://stackoverflow.com/questions/8759905/concatenating-dir-constant-with-a-string-as-an-array-value-which-is-a-class). A workaround is to initialize with DIR in a constuctor.

schmunk42 commented 8 years ago

Thanks for reporting. I wonder why I do not see this issue?! Which PHP version and OS are you using?

sbrendtro commented 8 years ago

I have tried it on multiple Ubuntu 14.04.3 LTS boxes, running PHP 5.5.9.

I'm a bit confused as well as to how it could be working, since everything I read suggests this behavior of PHP is intentional and won't likely be changing anytime soon. Thanks again!

sbrendtro commented 8 years ago

This seems to be similar to this issue on the yii2-pages-module: https://github.com/dmstr/yii2-pages-module/issues/2

schmunk42 commented 8 years ago

Fixed in https://github.com/phundament/app/commit/56c5c507254b938c35ce1906d8a91fff035e15ef

Seems no problem on 5.6. but it's clearer this way. I'll also update pages - thanks again.

schmunk42 commented 8 years ago

Should be fixed also for pages via https://github.com/phundament/app/commit/3c505f8998adc8cbf2be397f077fba8c41ddb6c0