Hi,
You could see it this way : getPrototype() will get you the information on
where your function has been "declared" in the first place. If we extend your
example:
<?php
class Hello {
public function sayHelloTo($name) {
}
}
class HelloWorld extends Hello {
public function sayHelloTo($name) { }
public function sayHi() { }
}
class HelloUniverse extends HelloWorld {
public function sayHelloTo($name) { }
}
/*
* Will output: Hello::sayHelloTo
*/
$reflectionMethod = new ReflectionMethod('HelloUniverse', 'sayHelloTo');
$prototype = $reflectionMethod->getPrototype();
echo $prototype->class . '::' . $prototype->name;
/*
* Will throw an exception
*/
$reflectionMethod = new ReflectionMethod('HelloWorld', 'sayHi');
$prototype = $reflectionMethod->getPrototype();
echo $prototype->class . '::' . $prototype->name;
So in the case of sayHelloTo() , the prototype is Hello::sayHelloTo. And in the
other case, there is no prototype for sayHi(), generating the exception. It
explains also why trying to get the prototype on Hello doesn't work.
You should get the result you want by doing:
echo $reflectionMethod->getDeclaringClass()->getName() . "::" .
$reflectionMethod->getName();
Regards,
________________
Michel Bartz
Lead Developer
Manwin Canada
ICQ: 409728761
Skype: michel.php
-----Original Message-----
From: Frederic Hardy [mailto:[email protected]]
Sent: Saturday, August 21, 2010 11:20 AM
To: PHP internals
Subject: [PHP-DEV] Bug in reflectionMethod::getPrototype() ?
Hello !
During french PHP test fest, i have tested
ReflectionMethod::getPrototype(), and the result is... strange.
This is the PHPT file :
--TEST--
--FILE--
<?php
class Hello {
public function sayHelloTo($name) {}
}
class HelloWorld extends Hello {
public function sayHelloTo($name) {}
}
$reflectionMethod = new ReflectionMethod('HelloWorld', 'sayHelloTo');
$prototype = $reflectionMethod->getPrototype();
echo $prototype->class . '::' . $prototype->name;
?>
--EXPECT--
Hello::sayHelloTo
In my opinion, result is strange because i'm expecting
HelloWorld::sayHelloTo instead of Hello::sayHelloTo.
More strange, if i'm using 'Hello' as class instead of 'HelloWorld' as
first argument of ReflectionMethod constructor,
ReflectionMethod::getPrototype() throw an exception because for PHP,
Hello::sayHelloTo() method has no prototype...
So, i think there is a problem.
Your opinion ?
Best regards,
Fred
--
========================================================================
Frédéric Hardy : Architecte d'application/Admin. système/Ergonome
Status : En recherche d'emploi
CV : http://blog.mageekbox.net/public/cv.frederic.hardy.pdf
Blog : http://blog.mageekbox.net
Twitter : http://twitter.com/mageekguy
========================================================================
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
This e-mail may be privileged and/or confidential, and the sender does not
waive any related rights and obligations. Any distribution, use or copying of
this e-mail or the information it contains by other than an intended recipient
is unauthorized. If you received this e-mail in error, please advise me (by
return e-mail or otherwise) immediately.
Ce courrier électronique est confidentiel et protégé. L'expéditeur ne renonce
pas aux droits et obligations qui s'y rapportent. Toute diffusion, utilisation
ou copie de ce message ou des renseignements qu'il contient par une personne
autre que le (les) destinataire(s) désigné(s) est interdite. Si vous recevez ce
courrier électronique par erreur, veuillez m'en aviser immédiatement, par
retour de courrier électronique ou par un autre moyen.
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php