|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42009 is_subclass_of: behaviour contradicts is_a.phpt testcase description
Submitted: 2007-07-16 15:02 UTC Modified: 2007-12-03 16:39 UTC
From: robin_fernandes at uk dot ibm dot com Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: PHP 5.3.0-dev (cli) (built: Nov 27 2007 16:18:57) OS: *
Private report: No CVE-ID: None
 [2007-07-16 15:02 UTC] robin_fernandes at uk dot ibm dot com
This is either a minor mistake in a testcase description, or a bug in is_subclass_of().

The description of testcase states:
"is_a() and is_subclass_of() shouldn't call __autoload".

However, the expected output explicitly checks for __autoload() calls *in some cases* (lines 49 and 50).

Either the testcase description (and perhaps documentation) should clarify in which circumstances is_subclass_of() does result in an invocation of __autoload(), or is_subclass_of() should be fixed.

Below is a simplified testcase illustrating a case where is_subclass_of() does invoke __autoload().

Reproduce code:
function __autoload($name) {
  echo("AUTOLOAD '$name'\n");
Class Def {}
var_dump(is_subclass_of("Def", "Undef"));

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-17 20:13 UTC]
According to the commit log is_a() and is_subclass_of() should NOT call __autoload, in the same way as "instanceof" operator.

But indeed the is_a.phpt does have check to see if __autoload was called and expects it -> there's bug somewhere. 

Dmitry, please check this out.
 [2007-08-22 13:24 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

 [2007-12-03 15:46 UTC] robin_fernandes at uk dot ibm dot com
This has been fixed for the second argument passed to is_subclass_of(), but not the first.

The test below shows that is_subclass_of() still invokes __autoload() for the first argument, contradicting the description (but not the content) of test is_a.phpt. Note that if this is fixed, the expected output for is_a.phpt will need to change.

---( Test case: )---
function __autoload($name) {
  echo("AUTOLOAD '$name'\n");
Class Def {}
var_dump(is_subclass_of("Undef", "Def"));

---( Expected output: )---
Warning: Unknown class passed as parameter in %s on line 6

---( Actual output: )---

Warning: Unknown class passed as parameter in %s on line 6
 [2007-12-03 16:29 UTC]
is_subclass_of() doesn't call __autoload() in case if first atgument is an object. Because if it's an object its class ,all parent classes and implemented interfaces are already loaded.

In case if first arguments is string, PHP will call __autoload() for it. This is not a bug but expected behavior.
 [2007-12-03 16:39 UTC] robin_fernandes at uk dot ibm dot com
Thanks for the explanation. Would it be reasonable to change the description of the test is_a.phpt, which currently states: 
"is_a() and is_subclass_of() shouldn't call __autoload" ?
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Dec 02 15:01:28 2023 UTC