Created
October 15, 2012 14:45
-
-
Save tobiassjosten/3892865 to your computer and use it in GitHub Desktop.
phpwtf-constmember
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Holder | |
{ | |
const myConstant = 'Stabil'; | |
} | |
class Wrapper | |
{ | |
public $holder; | |
public function __construct(Holder $holder) | |
{ | |
$this->holder = $holder; | |
} | |
} | |
$holder = new Holder(); | |
$wrapper = new Wrapper($holder); | |
echo $holder::myConstant; | |
// 'Stabil' | |
$holder2 = $wrapper->holder; | |
echo $holder2::myConstant; | |
// 'Stabil' | |
echo $wrapper->holder::myConstant; | |
// PHP Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM, expecting | |
// ',' or ';' in /home/tobias/phpwtf.php on line 24 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On a 2nd thought, I think it's just a generic syntax failure. It's a bug I think, a friend of mine reminded about the similar historic PHP 4 quirk where the following code failed too:
so you always had to use the method over the previously defined reference.