Re: wrong behaviour with is_subclass_of() ??

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Johannes Mueller schreef:
Jochem Maas wrote:

B implements I

because B subclasses A and A implements I,
I is not a base class.

try the experiment with is_a() instead.

This was my starting point and is_subclass_of() was a sub-ordinate target, because i needed it on the class-side of life and not the instantiated way.

also you should preferablly use the instanceof syntax:

<?php
$a = new A;
$b = new B;
if ($a instanceof I)) echo "A implements I\n";
if ($b instanceof I)) echo "B implements I\n";

or use the return data from class_implements(), is_subclass_of()

class_implements() would solve all these problems were well!

specifically looks at base classes ("extends"), I'm a little
surprised that it even returns true for interfaces at all
("implements").

And this was the reason where it stops to make sense for me. And if you hadn't pointed this out, this would have been in my next email.

I think the reason for the current behaviour is that interface can be
seen as an 'is a' relationship. is_subclass_of() looks specifically
for an 'is a' relationship with regard to whatever is above in the
class heriarchy ... there is nothing above A so it will always return
false for A.

so it's a little odd, but logical at the same time ... now the namespaces
implementation as it currently stands ... that's a little psychotic :-)


Johannes



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux