Hi,
It seems that in the past few months ReflectionClass::getMethod() was
changed to throw an Exception if the method doesn't exist. I don't
understand the reasoning because as it's a reflection API I would expect it
to return false and not an exception. Exceptions should be thrown for
errors. As long as we don't have hasMethod() then I think this behavior is
wrong.
Can anyone shed some light on this? Why was this changed? Marcus?
Thanks,
Andi
Hi,
It seems that in the past few months ReflectionClass::getMethod() was
changed to throw an Exception if the method doesn't exist.
-- snip --
revision 1.113
date: 2004/07/19 19:14:10; author: sebastian; state: Exp; lines: +9
-5
Make ReflectionClass::getMethod() and ReflectionClass::getProperty()
raise an ReflectionException instead of returning NULL
on failure.
-- snip --
I don't understand the reasoning because as it's a reflection API I
would expect it to return false
NULL
would be better, IMO, but nevertheless.
and not an exception. Exceptions should be thrown for errors. As long
as we don't have hasMethod() then I think this behavior is wrong.
Agreed.
Can anyone shed some light on this? Why was this changed? Marcus?
Ask Sebastian:)
I think what Sebastian wanted to do is:
$reflectionClass->getMethod('abc')->invoke($object);
...and not have this bail with a fatal error when getMethod() returns
NULL, but raise an exception. Fine. I still think NULL->method() should
throw a NullPointerError instead of bailing but I also agree with Andi
that as long as there is no hasMethod() throwing an exception is
unacceptable.
--
Timm
If it ain't broken, it doesn't have enough features yet
Hello Timm,
Thursday, December 23, 2004, 1:06:01 AM, you wrote:
Hi,
It seems that in the past few months ReflectionClass::getMethod() was
changed to throw an Exception if the method doesn't exist.
-- snip --
revision 1.113
date: 2004/07/19 19:14:10; author: sebastian; state: Exp; lines: +9
-5
Make ReflectionClass::getMethod() and ReflectionClass::getProperty()
raise an ReflectionException instead of returningNULL
on failure.
-- snip --
I don't understand the reasoning because as it's a reflection API I
would expect it to return false
NULL
would be better, IMO, but nevertheless.
and not an exception. Exceptions should be thrown for errors. As long
as we don't have hasMethod() then I think this behavior is wrong.
Agreed.
Can anyone shed some light on this? Why was this changed? Marcus?
Ask Sebastian:)
I think what Sebastian wanted to do is:
$reflectionClass->getMethod('abc')->invoke($object);
...and not have this bail with a fatal error when getMethod() returns
NULL, but raise an exception. Fine. I still think NULL->method() should
throw a NullPointerError instead of bailing but I also agree with Andi
that as long as there is no hasMethod() throwing an exception is
unacceptable.
While i think using exceptions consistently everywhere in Reflection API
is a good idea i also think we should have hasMethod() in either way.
Best regards,
Marcus mailto:helly@php.net
Thanks Timm.
Sebastian, what do you think?
Andi
At 01:06 AM 12/23/2004 +0100, Timm Friebe wrote:
Hi,
It seems that in the past few months ReflectionClass::getMethod() was
changed to throw an Exception if the method doesn't exist.-- snip --
revision 1.113
date: 2004/07/19 19:14:10; author: sebastian; state: Exp; lines: +9
-5
Make ReflectionClass::getMethod() and ReflectionClass::getProperty()
raise an ReflectionException instead of returningNULL
on failure.
-- snip --I don't understand the reasoning because as it's a reflection API I
would expect it to return falseNULL would be better, IMO, but nevertheless.
and not an exception. Exceptions should be thrown for errors. As long
as we don't have hasMethod() then I think this behavior is wrong.Agreed.
Can anyone shed some light on this? Why was this changed? Marcus?
Ask Sebastian:)
I think what Sebastian wanted to do is:
$reflectionClass->getMethod('abc')->invoke($object);
...and not have this bail with a fatal error when getMethod() returns
NULL, but raise an exception. Fine. I still think NULL->method() should
throw a NullPointerError instead of bailing but I also agree with Andi
that as long as there is no hasMethod() throwing an exception is
unacceptable.--
Timm
If it ain't broken, it doesn't have enough features yet
Andi Gutmans wrote:
Exceptions should be thrown for errors.
And trying to get a method that does not exist is an error.
Can anyone shed some light on this? Why was this changed?
To make consistent use of ReflectionException, IIRC.
For instance, the following code
<?php
$method = new ReflectionMethod(
'NotExistingClass',
'notExistingMethod'
);
?>
throws an ReflectionException as well. Now one could argue that there
is no other way to signal an error in the __construct() than to use
methods, but I think it is better to use the same error signalling in
bith ReflectionClass::getMethod() and ReflectionMethod::__construct().
And besides, it is what Java does [1], so we cannot be that far off :-)
Seasons's Greetings,
Sebastian
--
[1] http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html
--
Sebastian Bergmann http://www.sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69
Sebastian Bergmann wrote:
methods, but I think it is better to use the same error signalling in
- methods,
- exception,
--
Sebastian Bergmann http://www.sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69
Andi Gutmans wrote:
Exceptions should be thrown for errors.
And trying to get a method that does not exist is an error.
...which is fine, but without an elegant way of checking if that method
exists I don't think it should be done.
I think we could all agree on
bool hasMethod(string $name)
(and not changing getMethod()) though, right?
--
Timm
If it ain't broken, it doesn't have enough features yet
Timm Friebe wrote:
I think we could all agree on
bool hasMethod(string $name)
(and not changing getMethod()) though, right?
Yes, although I do not think that hasMethod() is really needed.
--
Sebastian Bergmann http://www.sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69