Re: Fix for #53727 (is_subclass_of resolution with interfaces)
| From: | Ralph Schindler | Date: | Wed, 29 Jun 2011 21:24:54 +0000 |
| Subject: | Re: Fix for #53727 (is_subclass_of resolution with interfaces) | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-53686@lists.php.net to get a copy of this message | ||
Hey Paul,
The only thing we are attempting to do here is make is_subclass_of() more consistent when using class names (strings), something instanceof cannot handle.
Given the following:
interface A {}
class B implements A {}
class C extends B {}
// currently false, and correct as B is not a subclass of B
var_dump(is_subclass_of('B', 'B'));
// currently false, but SHOULD be true
var_dump(is_subclass_of('B', 'A'));
// true since C's parent class is B
var_dump(is_subclass_of('C', 'B'));
// currently true, but inconsistent with is_subclass_of('B', 'A')
// why should having a parent matter?
var_dump(is_subclass_of('C', 'A'));
Currently, this (pseudo-code) is the workaround in ZF2 we are finding ourselves go with:
function someFunc($class, $type) {
return (array_key_exists(
$type,
(class_parents($class, true) + class_implements($class, true)
));
}
-ralph
On 6/29/11 3:20 PM, Paul Dragoonis wrote:
On Wed, Jun 29, 2011 at 8:49 PM, Ralph Schindler<ralph@smashlabs.com> wrote:Correct. I was hasty in that example, the first was copied& tested (and is reflected in the test, as is that variation of what I wrote up.) Either way, test and patch work in 5_3.Doesn't this functionality confuse matters? If this patch is added, is there now no difference between instanceof and is_subclass_of(). If this is the case my question is then why do we have two methods to do the same thing? I thought instanceof was for parent classes + interfaces.. and is_subclass_of() was just for parent classes. Regards, Paul Dragoonis.Thanks, -ralph On 6/29/11 2:42 PM, David Zülke wrote:On 29.06.2011, at 21:39, Ralph Schindler wrote:-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.phpinterface A {} class B implements A {} class C extends B {} var_dump(is_subclass_of('B', 'A')); // trueTypo there; that should be 'C', not 'B'. David