|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-12-09 15:47 UTC] exsystemchina at gmail dot com
Description: ------------ A weird bug, appears only when the script contains require_once: A class is defined with an interface implemented, but the PHP interpreter produces a fatal error saying class not defined. But everything goes well if the class doesn't implemented an interface. Test script: --------------- Download this file, and unzip it: http://files.cnblogs.com/ExSystem/FrameworkDSW.zip Make sure your php include_path contains the parent directory of FrameworkDSW, and to set error reporting level to E_ALL in case. Run FrameworkDSW\System.php, and get the fatal error. ****And only the classes defined before the declaration of TObject inside System.php are declared succesfully(I guess it by invoking get_declared_classes()). Then modify the line 285 of System.php to class TObject { rather than class TObject implements IInterface { and run it again, to see the difference. ****And all the classes inside System.php are declared successfully. Expected result: ---------------- <Nothing> Actual result: -------------- <br /> <b>Fatal error</b>: Class 'TObject' not found in <b>{your_include_path}\FrameworkDSW\Utilities.php</b> on line <b>81</b><br /> PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 08 07:00:01 2025 UTC |
//System.php <?php require_once 'Utilities.php'; class TJustTest { public function __construct() { var_dump(get_declared_classes()); } } interface IInterface { public function Supports($AInterface); } class TObject implements IInterface { public function Supports($AInterface) { echo 'hi'; } } class TJustAnotherTest { public function Foo() { echo 'foo'; } } ?> //Utilities.php <?php require_once 'System.php'; class TSomethingBoring { public function Boring() { echo 'really boring'; } } $a=new TJustTest(); class TMustBeWrong extends TObject { function Tragedy() { echo 'this will not be seen.'; } } ?> Just run System.php to see the fatal error with other classes before TObject loaded successfully inside System.php