|  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
47 - 11 = ?
Subscribe to this entry?

 [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 27 03:01:30 2024 UTC