Skip to content

Instantly share code, notes, and snippets.

@woprrr
Created November 5, 2018 10:09
Show Gist options
  • Save woprrr/042fee64c9d46096a717dd84e4982271 to your computer and use it in GitHub Desktop.
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().
<?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