Love Fuel?
Donate
About
Forums
Discussions
Login
FuelPHP Forums
Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
General
Static variable and Constant
akimad
April 2015
Hi,
I've declared a static variable in my class but I've got an error. Here my variable :
private static $projects_images_folder = DOCROOT.'assets'.DS.'v1'.DS.'img'.DS.'projects'.DS;
And I've got this error :
ErrorException [ Parsing Error ]:
syntax error, unexpected '.', expecting ',' or ';'
I don't understand why. If I set my variable to "test", it works. If I set to DOCROOT only, it works too. But when I use concatenation, it doesn't work.
Thank you for your help.
kenjis
April 2015
Accepted Answer
You can't. It is PHP spec.
> Like any other PHP static variable, static properties may only be
initialized using a literal or constant; expressions are not
allowed.
http://php.net/manual/en/language.oop5.static.php
Harro
April 2015
Accepted Answer
You can get around it using:
protected
static $projects_images_folder
;
public static function _init()
{
static::$projects_images_folder = DOCROOT.'assets'.DS.'v1'.DS.'img'.DS.'projects'.DS;
}
akimad
April 2015
Ok I understand.
Thank you very much
:)
Add a Comment
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
5,088
General
↳ General
3,364
↳ Job Board
13
↳ Installation & Setup
214
Packages
↳ Oil
213
↳ Orm
700
↳ Auth
260
Development
↳ Tips and Tutorials
126
↳ Code share
145
↳ Applications
52
In this Discussion
akimad
April 2015
Harro
April 2015
kenjis
April 2015