|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-08-12 22:41 UTC] sniper@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 04 21:00:02 2025 UTC |
Description: ------------ I've been toying around a bit with the __autoload() functionallity and along the way found some strange behaviour. I'm not entirely sure it's bug, but it's at least not working as I would expect it. I created a system which allows classes to register themselfs with a "registration object" when loaded. When registering, some checks are executed to (for example) see if the class that's being registered is of the right type. Below is a very simplified version of my script, it serves no purpose but to show my problem. Reproduce code: --------------- Index.php <?php function __autoload($class){ include($class . '.php');} $Class = new Class2(); ?> Class1.php <?php class Class1{ public static function CheckClass2(){ is_subclass_of('Class2', 'Class1');}} ?> Class2.php <?php Class1::CheckClass2(); class Class2 extends Class1{} ?> Expected result: ---------------- When running Index.php, a blank page should be displayed. Actual result: -------------- When running Index.php, the following error appears: Warning: Unknown class passed as parameter in Class1.php on line 7 I can only assume that by using the __autload() function the normal flow of code processing is changed in some way. Class2 seems not to be defined by the time the CheckClass2() method is called, even though Class2.php should've been included before Class1.php (where this method is located). When I manually include both files in Index.php the code works fine, same goes for placing the call to CheckClass2() below the definition of Class2. Again, I'm not sure whether this is a bug or just "the way it works". It's although not what I would expect to happen...