ID:               20333
 Updated by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
-Status:           Open
+Status:           Bogus
 Bug Type:         Class/Object related
 Operating System: Linux
 PHP Version:      4.2.3
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


Previous Comments:
------------------------------------------------------------------------

[2002-11-09 22:56:29] [EMAIL PROTECTED]

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 this bug report at http://bugs.php.net/?id=20333&edit=1

Reply via email to