#20333 [NEW]: A return() in an include won't skip registering classes below

From: Date: Sun, 10 Nov 2002 04:56:29 +0000
Subject: #20333 [NEW]: A return() in an include won't skip registering classes below
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-24419@lists.php.net to get a copy of this message
From: mgv@fx.ro Operating system: Linux PHP version: 4.2.3 PHP Bug Type: Class/Object related Bug description: A return() in an include won't skip registering classes below When including a file which contains a class definition, performing a return() ABOVE the class definition will still result in the class being registered, if the class is completely new or if it extends a defined class. The same with functions. I believe this has to do with PHP 4 not caring where a function/class is declared in a script, so I expect PHP performs some pre-registration of these items before executing the actual code in the script. This behaviour is unexpected however when the user wants to perform an explicit return() before the class definition. Although not really needed, here's an example demonstrating this behaviour: -- myFile.php -- <? include("myLib.php"); // This will be defined if (class_exists("myclass")) { echo("Original class IS defined!<br />"); } else { echo("Original class IS NOT defined!<br />"); } // This will be defined if (class_exists("myclass_ex")) { echo("Extended original class IS defined!<br />"); } else { echo("Extended original class IS NOT defined!<br />"); } // This will NOT be defined if (class_exists("yourclass_ex")) { echo("Extended non-existent class is defined!<br />"); } else { echo("Extended non-existent class IS NOT defined!<br />"); } // This will be defined if (function_exists("myfunc")) { echo("Function IS defined!<br />"); } else { echo("Function IS NOT defined!<br />"); } ?> -- myLib.php -- <? return(1); // Code won't execute echo("Whoaa! return() didn't do a thing!"); // Class will however be defined class myClass {} // Extended class of defined class will be defined class myClass_ex extends myClass {} // Extended class of undefined class will NOT be defined however class yourClass_ex extends yourClass {} // But a plain function will be defined function myFunc() {} ?> You can see the code in action at http://bogdan.lanifex.com/PHP_include_test/myFile.php (a highlight_file(__FILE__) is added in both files for clarity at that URL). -- Edit bug report at http://bugs.php.net/?id=20333&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=20333&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=20333&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=20333&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=20333&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=20333&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=20333&r=support Expected behavior: http://bugs.php.net/fix.php?id=20333&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=20333&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=20333&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=20333&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=20333&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=20333&r=dst IIS Stability: http://bugs.php.net/fix.php?id=20333&r=isapi

« previous php.bugs (#24419) next »