Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Static variable and Constant
  • 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.
  • kenjiskenjis
    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

  • HarroHarro
    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;
    }
  • Ok I understand.

    Thank you very much :)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion