|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-01-15 02:05 UTC] aalbre99 at student dot hia dot no
Description:
------------
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):
//require_once("class_files/ErrorFetcher.php");
//"fixes" the problem
Reproduce code:
---------------
//(test.php)
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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 22:00:01 2025 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 TechnologiesI 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'... /test.php /class_files/ErrorHandler.php /class_files/TestClass.php /other/Other.php #test.php# <?php function __autoload($className) { require_once("class_files/" . $className . ".php"); } //Uncoment this line to bypas the bug... //require_once("class_files/TestClass.php"); class Test { public function Test() { $errorHandler = new ErrorHandler(); require_once("Other/Other.php"); $other = new Other(); } } $test = new Test(); ?> #TestClass.php# <?php class TestClass { public static $staticVar; public function TestClass() { //Set ErrorHandler set_error_handler(array($this, 'handlePhpError')); } } ?> #ErrorHandler.php# <?php class ErrorHandler { public function ErrorHandler() { error_reporting(E_ALL); set_error_handler(array($this, 'handlePhpError')); } public function handlePhpError($type, $msg, $file, $line) { $myVar = TestClass::$staticVar; echo "Error!"; } } ?> #Other.php# <?php class Other { //Produces warning! var $temp = 'temp'; public function Other() {} } ?>