Skip to content

Instantly share code, notes, and snippets.

@timperrett
Created October 2, 2012 22:41
Show Gist options
  • Select an option

  • Save timperrett/3823786 to your computer and use it in GitHub Desktop.

Select an option

Save timperrett/3823786 to your computer and use it in GitHub Desktop.
Stupid stuff PHP does.
<?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