Created
October 2, 2012 22:41
-
-
Save timperrett/3823786 to your computer and use it in GitHub Desktop.
Stupid stuff PHP does.
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 | |
| // set a value | |
| $theCount = 123; | |
| // set a string that happens to be the same name as the | |
| // previous (unrelated) value | |
| $someString = 'theCount'; | |
| // print out the string... oh... WAT. | |
| echo $$someString; // echo's 123 | |
| echo "\n"; | |
| class Foo { | |
| public function bar(){ | |
| return "hello world"; | |
| } | |
| }; | |
| // intended usage | |
| $foo = new Foo(); | |
| echo $foo->bar(); | |
| echo "\n"; | |
| // assign some strings | |
| $klass = 'Foo'; | |
| $method = 'bar'; | |
| // make a new... wait...wtf... that didnt exist so you must | |
| // want me to make a new Foo instance, ok, lets do that. | |
| $foo2 = new $klass(); | |
| // attempt to call an arbitrary string method on the | |
| // auto-loaded instance (which was also pulled from a string) | |
| echo $foo2->$method(); | |
| echo "\n"; | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment