Skip to content

Instantly share code, notes, and snippets.

@dsci
Created November 12, 2018 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsci/010c69248f42dc9653aa324386853640 to your computer and use it in GitHub Desktop.
Save dsci/010c69248f42dc9653aa324386853640 to your computer and use it in GitHub Desktop.
Reflection PHP
<?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