Skip to content

Instantly share code, notes, and snippets.

@dsci
Created November 12, 2018 14:30
Show Gist options
  • 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