Created
April 23, 2013 16:08
-
-
Save nielsmh/5444959 to your computer and use it in GitHub Desktop.
Crazy PHP. Consistency, don't need that. You can apply the "new" operator to a variable containing a string, but you can't apply it to a string literal. Why are those two different at all?
This file contains hidden or 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 -a | |
Interactive shell | |
php > class Lol { } | |
php > $a = new Lol; | |
php > var_dump($a); | |
object(Lol)#1 (0) { | |
} | |
php > $b = new 'Lol'; | |
PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in php shell code on line 1 | |
php > $b = 'Lol'; | |
php > $bb = new $b; | |
php > var_dump($bb); | |
object(Lol)#2 (0) { | |
} | |
php > $c = 1; | |
php > $cc = new $c; | |
PHP Fatal error: Class name must be a valid object or a string in php shell code on line 1 | |
$ _ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment