Does this work in PHP5.3?

I am running 5.2.6, can anyone tell me if this works in 5.3?

(I get T_PAAMAYIM_NEKUDOTAYIM)


class obj {

static function foo(){

return "bar" ;
}

}

$a = 'ob' ;
$b = 'foo' ;

$i = $a::$b ;

echo $i ;

Thanks :slight_smile:

Your class is called ‘obj’, $a contains ‘ob’… why should that work in any version?

PHP 5.3.3-0.dotdeb.1 with Suhosin-Patch (cli)

After changing $a from ‘ob’ to ‘obj’ (I assumed it was a typo):

PHP Fatal error: Access to undeclared static property: obj::$b in …

Yes, it was a typo, sorry about that… [red face]

furicane, yes you guessed correctly, should have been:


class obj {

static function foo(){
return "bar" ;
}
}

$a = 'obj' ; //<-fixed typo
$b = 'foo' ;

$i = $a::$b();  //<-added brackets !!

echo $i ; 

So, it does not work in PHP 5.3 either, but comes out with a different (fatal) error message?

Whatabout with the brackets added?

With brackets it echoes “bar”.

Thank you very much furicane, apologies both for my bad original example too.

No prob. I thought it might be a typo, but it could’ve been the reason as well, that’s why I pointed it out.

No prob.

Paste in haste causes waste, and not to my taste - I come away red faced.

It’s no problem, I totally understand when someone makes typos :slight_smile: