Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 5 down vote accepted
protected static $test = 'A TEST';
                 ^--- !!!

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

share|improve this answer
    
Heh, always overlooking the simple things. –  Ryan_K Jul 18 '12 at 20:40
    
@Ryan_K consider clicking on the green tick next to the answer to accept it if it helped. –  Mahn Jul 18 '12 at 20:46
    
Yeah, had to wait before choosing an answer. (Which is a nice implementation) –  Ryan_K Jul 18 '12 at 20:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.