Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP 5.6.* vs 7.0.* syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM)

Tags:

php-7

Strange my research has not turned'up this exact scenario:

$someVar = $this->StaticClassName::$staticClassProperty;

php 7.* happily accesses the property but 5.6.* (.11 in this case) falls over with the error:

unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM)

And yes, I've tried every ${permutation}:: I could think of.

like image 880
CNSKnight Avatar asked Jul 30 '16 01:07

CNSKnight


1 Answers

There's a lot of compound expressions like this which don't work in PHP 5. Usually the solution is to break it into multiple expressions, and you can do that here:

$className = $this->StaticClassName;
$someVar = $className::$staticClassProperty;

This works on both PHP 5 and PHP 7.

like image 52
Andrea Avatar answered Oct 27 '22 21:10

Andrea