Unexpected T_PAAMAYIM_NEKUDOTAYIM in PHP 5.2.x

后端 未结 5 1355
情深已故
情深已故 2020-12-18 07:39

I\'m having a hard time understanding why I\'m getting an Unexpected T_PAAMAYIM_NEKUDOTAYIM error in the following code, which seems perfecly valid to me...

5条回答
  •  無奈伤痛
    2020-12-18 08:05

    The reason for the error is simply that the syntax isn't supported in < 5.3.

    However, if you're trying to just access the static variable $id, then the syntax would be:

    $result::id

    If you do need to access a static variable variable, then a workaround is to use reflection:

    $class = new ReflectionClass($xpto);
    echo $class->setStaticPropertyValue ('id', strval($xpto));
    

    ReflectionClass

提交回复
热议问题