开发者

Parse error: syntax error, unexpected T_STATIC [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.
class Employee 
{
    public static $favSport = "Football";

    public static function watchTV()
  开发者_如何学编程  {
        echo "Watching ".static::$favSport;
    }
}

class Executive extends Employee 
{
    public static $favSport = "Polo";
}

echo Executive::watchTV();

Parse error: syntax error, unexpected T_STATIC on line 7

Why do I get parse error & and how to fix it? Thanks!


The parse error here:

echo "Watching ".static::$favSport;

is because late static bindings were introduced in PHP v5.3. Your php version (<5.3) doesn't recognize static::$favSport.

There isn't any way I can think of to fix it for PHP older than 5.3, other than with object inheritance (which isn't really a fix per se since it doesn't have anything to do with static)...


I had the same problem, but i used self in the place of static for my php version that's 5.2.1 well older than 5.3 http://php.net/manual/en/language.oop5.late-static-bindings.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜