|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31562 __autoload() problem with static variables
Submitted: 2005-01-15 02:05 UTC Modified: 2005-03-10 03:34 UTC
From: aalbre99 at student dot hia dot no Assigned: helly
Status: Closed Package: Scripting Engine problem
PHP Version: 5.* OS: *
Private report: No CVE-ID:
 [2005-01-15 02:05 UTC] aalbre99 at student dot hia dot no
Autoload is not invoked for missing class when using static variables (no other reference to the class in same file).

Ex. (test.php):
function __autoload($className) {	
	require_once("class_files/" . $className . ".php");
$myVar = MyClass::$classVar;

//This will not invoke the __autoload() procedure...
//Adding (in the top):
//"fixes" the problem

Reproduce code:

function __autoload($className) {	
	require_once("class_files/" . $className . ".php");

$myVar = MyClass::$classVar;

//MyClass is described in class_files/MyClass.php...

Expected result:
No error...

Actual result:
Fatal error: Class 'MyClass' not found in test.php on line xx


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-15 07:43 UTC]
Anything unusual about your configuration? i.e., php.ini changes or Zend extensions? I cannot reproduce this.

F:\>php_5_0_3 -f F:\test.php                                                   
Warning: __autoload(class_files/MyClass.php): failed to open stream: No such file or directory in F:\test.php on line 3                                         
Fatal error: __autoload(): Failed opening required 'class_files/MyClass.php' (include_path='.;D:\PHP\PHP_5_0_3\include') in F:\test.php on line 3                           
F:\>php5_0_3 -v                                                               
PHP 5.0.3 (cli) (built: Dec 15 2004 08:07:57)                                   
Copyright (c) 1997-2004 The PHP Group                                           
Zend Engine v2.0.3, Copyright (c) 1998-2004 Zend Technologies                   
 [2005-01-15 12:40 UTC] aalbre99 at student dot hia dot no
Thought it was a general bug, but it's not...

If you replace 
"$myVar = MyClass::$classVar;"
"$myVar = ErrorFetcher::$classVar;"
you will se the error...

Is this a bug, or is it me how have chosen a bad name for my class....?
 [2005-01-15 12:56 UTC] aalbre99 at student dot hia dot no
This is the strangest thing...

Today my PHP application works fine, but I am sure that it didn't work yesterday. No changes in the code, only a reboot of my computer since yesterday....
 [2005-01-15 13:06 UTC] aalbre99 at student dot hia dot no
YES. I managed to reproduce the error in my PHP application!
(One line was changed...)

I will now try to make a test application I can post here which generates the same error... Stay tuned...
 [2005-01-15 13:51 UTC] aalbre99 at student dot hia dot no
I have created an application which reproduces the error. And now I see that the error is caused by something other than I thought in the beginning...

Put the following files in the following folder structure, and load 'test.php'...


function __autoload($className) {	
	require_once("class_files/" . $className . ".php");

//Uncoment this line to bypas the bug...

class Test
	public function Test()
		$errorHandler = new ErrorHandler();
		$other = new Other();			

$test = new Test();

class TestClass
	public static $staticVar;
	public function TestClass()
		//Set ErrorHandler
		set_error_handler(array($this, 'handlePhpError'));		

class ErrorHandler
	public function ErrorHandler()
		set_error_handler(array($this, 'handlePhpError'));		
	public function handlePhpError($type, $msg, $file, $line)	
		$myVar = TestClass::$staticVar;	
		echo "Error!";			

class Other 
	//Produces warning!
	var $temp = 'temp';
	public function Other()	{}	
 [2005-02-28 21:02 UTC]
Please try using this CVS snapshot:
For Windows:

 [2005-03-06 22:59 UTC] aalbre99 at student dot hia dot no

Replaced all my PHP files with the files in

Still same error...

(I'am using the built-in IIS in Windows XP SP2)

 Output from 'test.php':

Fatal error: Class 'TestClass' not found in
C:\_ECLIPSE_\test\other\Other.php on line 5
 [2005-03-10 03:34 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.

 [2011-04-21 13:21 UTC] liujingfeng at snda dot com
I get the same bug. My php ver is 5.2 .
 [2013-08-30 09:35 UTC] youcontrol at foxmail dot com
I got a same error,too!
php 5.2
PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Sun Nov 29 21:01:32 2015 UTC