1

Testing some late static binding and getting this error on line 5:

Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE

line 5:

protected static test = 'A TEST';

Here is the source:

class A {

    protected static test = 'A TEST';

    public static function test() {
        echo $this->test;
    }
}

Class B extends A {
    public static test = "B TEST";
    public function static_test() {
        echo static::$test;
    }
}

$a = new A;
$b = new B;

echo '$a->test()<br />';
echo $a->test();
echo '<br /> <br />';
echo '$b->test()<br />';
echo $b->test();
echo '<br /> <br />';
echo '$b->static_test()<br />';
echo $b->static_test();

Safe to say I am stumped.

1 Answer 1

5
protected static $test = 'A TEST';
                 ^--- !!!

It's not a constant - so it should be preceded by $ sign

Sign up to request clarification or add additional context in comments.

3 Comments

Heh, always overlooking the simple things.
@Ryan_K consider clicking on the green tick next to the answer to accept it if it helped.
Yeah, had to wait before choosing an answer. (Which is a nice implementation)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.