|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44021 is_subclass_of Does Not Accept Namespaces
Submitted: 2008-02-02 02:01 UTC Modified: 2008-02-02 05:47 UTC
From: rpanning at hotmail dot com Assigned:
Status: Closed Package: Class/Object related
PHP Version: 5.3CVS-2008-02-02 (snap) OS: Windows XP SP2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: rpanning at hotmail dot com
New email:
PHP Version: OS:


 [2008-02-02 02:01 UTC] rpanning at hotmail dot com
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:

Actual result:
Warning: Unknown class passed as parameter in C:\test.php on line 7


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-02 03:35 UTC]
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:

namespace Foo;
function testsit($cl)
    return is_subclass_of($cl, 'ParentClass');

Now, if one calls this code from this file:

namespace Blah;

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.
 [2008-02-02 05:47 UTC] rpanning at hotmail dot com
Alright, that does work and I did further testing and it seems to work. Unfortunately I deleted my original tests so I cannot determine what I was originally trying. Thanks
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 20 12:01:33 2024 UTC