|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-02-02 02:01 UTC] rpanning at hotmail dot com
Description:
------------
The is_subclass_of() function does not accept classes in namespaces. A warning is generated and the statement results as FALSE.
Also, in the example, if the namespace definition is removed it works.
Reproduce code:
---------------
namespace NS;
class ParentClass {}
class ChildClass extends ParentClass {}
if (is_subclass_of('ChildClass', 'ParentClass')) {
print 'Yes';
} else {
print 'No';
}
Expected result:
----------------
Yes
Actual result:
--------------
Warning: Unknown class passed as parameter in C:\test.php on line 7
No
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 16:00:01 2025 UTC |
<?php namespace NS; class ParentClass {} class ChildClass extends ParentClass {} if (is_subclass_of('NS::ChildClass', 'NS::ParentClass')) { print 'Yes'; } else { print 'No'; } ?> Does the above code work for you? If yes, please close this bug as bogus. Automatic prefixing only occurs with absolute classnames, not compiled variables. Imagine, for instance this code: <?php namespace Foo; function testsit($cl) { return is_subclass_of($cl, 'ParentClass'); } ?> Now, if one calls this code from this file: <?php namespace Blah; var_dump(testsit('ChildClass')); ?> should it look for Blah::ChildClass, Foo::ChildClass, or ::ChildClass? There is no deterministic way to answer this question. Therefore fully qualified classnames must be used for anything that isn't a T_STRING.