Created
November 12, 2018 14:30
-
-
Save dsci/010c69248f42dc9653aa324386853640 to your computer and use it in GitHub Desktop.
Reflection PHP
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 | |
// example code | |
function dynamicCall($someMsg) { | |
try { | |
$method = new ReflectionMethod('Foo', $someMsg); | |
$method->invoke(new Foo()); | |
}catch(Exception $error){ | |
exitTheHell($error); | |
} | |
} | |
function exitTheHell($e){ | |
$errorMsg = 'Caught exception: '.$e->getMessage(); | |
print($errorMsg); | |
} | |
class Foo { | |
function addElement(){ | |
print("dynamic call"); | |
} | |
} | |
dynamicCall("addElement"); | |
dynamicCall("lost"); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment