Created
November 5, 2018 10:09
-
-
Save woprrr/042fee64c9d46096a717dd84e4982271 to your computer and use it in GitHub Desktop.
That gist demonstrate simply when use is_callable / __call instead of method_exist to avoid all visibility problems induced by method_exist().
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 | |
class LaBase { | |
// private function foobar() {return true;} | |
// public function foobar() {return true;} | |
} | |
class NoMagic extends LaBase { | |
function isParentFoobarCallable() { | |
return is_callable('parent::foobar'); | |
} | |
function methodExists(){return method_exist($this, 'foobar');} | |
} | |
class Magic extends NoMagic { | |
function __call($method, $args) {} | |
} | |
$nomagic = new NoMagic(); | |
var_dump($nomagic->isParentFoobarCallable()); | |
$magic = new Magic(); | |
var_dump($magic->isParentFoobarCallable());; | |
//var_dump($magic->methodExists()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment