2

I've got a class which works perfectly on localhost (PHP 5.6.10),

class Blog
{
    static $table = DBPREFIX . '_blog';

    // SELECTs
    static function getAll()
    {
        $query = 'SELECT * FROM '.self::$table.' WHERE active = 1 ORDER BY ord';
        return R::getRow($query);
    }
}

But when I put it in the server (PHP 5.5.27) it gives me an error on the static var because I'm concatenating the contant,

Parse error: syntax error, unexpected '.', expecting ',' or ';' in /models/Blog.php on line 3

Can anyone tell me which is the configuration that it's going wrong here?

Thanks,

Kup
  • 882
  • 14
  • 31
  • I've edited the question, I only had that comma because the query was larger, I just shortened it to make it easier to read – Kup Aug 13 '15 at 08:38
  • `php` states `Like any other PHP static variable, static properties may only be initialized using a literal or constant; expressions are not allowed.` – manjeet Aug 13 '15 at 08:39
  • sure, but why does it even work on localhost? must be some configuration on the php.ini right? – Kup Aug 13 '15 at 08:41
  • 1
    Might be E_STRICT mode – Mihai Aug 13 '15 at 08:42
  • 1
    Dynamic definitions (allowing the use of operations) for class properties was introduced in PHP version 5.6.0 – Mark Baker Aug 13 '15 at 08:44
  • Oh, ok, did not know that, thanks :) – Kup Aug 13 '15 at 08:45

1 Answers1

3

Dynamic definitions (allowing the use of operations) for class properties was introduced in PHP version 5.6.0

So a class property definition of

static $table = DBPREFIX . '_blog';

which uses the concatenation operator is valid in PHP >= 5.6.0 but not valid in earlier versions of PHP

EDIT

See the PHP 5.6 Changelog for details

Mark Baker
  • 209,507
  • 32
  • 346
  • 385
  • so in order to do this I really do need to use the __construct() and can't use it as a static right? – Kup Aug 13 '15 at 08:55
  • Or you need to upgrade your server to 5.6 if possible.... PHP 5.5 is now only in security updates for another 10 months before it reaches end of life – Mark Baker Aug 13 '15 at 09:34