I'm try to find a check for a magic method in reflection class, but it's not there. Maybe php (I'm using php 5.3) has some other instruments to resolve this problem? Something like this:
class myClass {
public function __call($method, $arguments)
{
return 'is magic';
}
public function notMagic()
{
return 'not a magic';
}
}
$reflection = new ReflectionMethod('myClass', 'magic');
if ($reflection->isMagic())
{
/* do something if is magic*/
}
Since PHP doesn't provide a way to check if a method is magic or not you have two options.
The docs say that
PHP reserves all function names starting with __ as magical. It is recommended that you do not use function names with __ in PHP unless you want some documented magic functionality.
You could therefore just check to see if the method name starts with __
:
if(strpos($methodName, '__') === 0){
echo "$methodName is magic";
}
The downside to this is that someone could make a method __myNewMethod
and it would be considered magical despite PHP not actually doing anything with it.
Alternatively you can have a whitelist of names. Again, according to the docs, the following methods are magical:
__construct(), __destruct(), __call(), __callStatic(),
__get(), __set(), __isset(), __unset(), __sleep(),
__wakeup(), __toString(), __invoke(), __set_state() and __clone()
The downside of this method is that future versions of PHP may add and remove from this list making the code incorrect.
The choice would probably depend on how you want to use this info.