php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38726 __autoload miss for is_subclass_of
Submitted: 2006-09-05 16:58 UTC Modified: 2006-09-13 01:00 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:1 (33.3%)
From: jiri dot brachtl at centrum dot cz Assigned:
Status: No Feedback Package: Class/Object related
PHP Version: 5.1.6 OS: Windows XP SP2
Private report: No CVE-ID: None
 [2006-09-05 16:58 UTC] jiri dot brachtl at centrum dot cz
Description:
------------
__autoload() fails to load class, when its name is used in the first parameter of is_sublass_of().

Reproduce code:
---------------
function __autoload($className) {
  require_once $className . ".php";
}

//Both ClassName1 and ClassName2 are defined in separate files

print_r(
  is_sublass_of("ClassName1", "ClassName2")
);

Expected result:
----------------
0 or 1

Actual result:
--------------
//nothing, like void return type

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-05 17:04 UTC] jiri dot brachtl at centrum dot cz
Missing 'c' in function name is_subclass_of. Not so important.
 [2006-09-05 17:09 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2006-09-05 17:10 UTC] tony2001@php.net
And please use var_dump() instead of print_r().
 [2006-09-13 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2007-09-10 18:06 UTC] dan dot marra at gmail dot com
The follow example was requested. This should reproduce the error:

<?php
   function __autoload($classname)
   {
       require_once('include/'.$classname.'.php');
   }

   // in include/foo.php
   class foo {
      private $myVar;
      private $myDerivedClass;

      function __construct()
      {
         $this->myDerivedClass = new Bar();
      }
      
      function getAllVars()
      {
         $values = get_object_vars($this);
         foreach($values as $property => $value)
	 {
	     if(is_subclass_of($value, 'Foo'))
	         die('is a subclass!');
         }
      }
    }

//in include/bar.php
class Bar extends Foo
{
      private $anotherValue

      function __construct()
      {
           $this->anotherValue = 'foobar';
      }
}

$myclass = new Foo();
$myclass->getAllVars();


?>


this causes a fatal error where it cannot include 'test 1.php'.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC