|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2002-11-10 05:11 UTC] derick@php.net
[2017-12-04 11:50 UTC] phpdoc at mail dot my1 dot info
[2017-12-04 11:57 UTC] spam2 at rhsoft dot net
[2017-12-04 12:41 UTC] phpdoc at mail dot my1 dot info
[2017-12-04 12:45 UTC] spam2 at rhsoft dot net
[2017-12-04 12:45 UTC] phpdoc at mail dot my1 dot info
[2017-12-04 12:52 UTC] spam2 at rhsoft dot net
[2017-12-04 13:01 UTC] phpdoc at mail dot my1 dot info
[2017-12-04 13:03 UTC] spam2 at rhsoft dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 22:00:01 2025 UTC |
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).