From:             fox000 at yandex dot ru
Operating system: windows XP
PHP version:      4.3.4
PHP Bug Type:     Scripting Engine problem
Bug description:  mindless in classes declaration ( class included in other class)

Description:
------------
"I am not sure whether this is a bug, a feature, or lack of a feature."

The class must be declared in a global scope. But there  no  explanation 
about class declarations that are included in function or in method of
other class.

If I would like to declare a class inside other class or function, I will 
have an error. But the strange is that, if I make an include into a
function or in class method, then all is working fine: my new class
declaration (included  from  other file) become normal  and  I  can  use 
the  class  as  global  declared  class. 



The question is: why class declaration not permitted inside the functions,
 but

it is possibly to load it in the function  using 

"include(...)" command.



Examples(1):

------- class_in_method.php ----------

<?php

//start

class glob

{

   var  $i;

   function glob1()

   {

      class incl

      {

         function incl_test()

         {

            return "result!!";

         }

      }



      $i=new incl();

      echo $i->incl_test();

   }

};

$g=new glob();

$g->glob1();

//end

?>

well, it not works, as listed in all manuals. It shows error:



Fatal error : Class declarations may not be nested.

---- end example(1) -----------



But when we are using include("...")



Examples(2):

-------- class_in_method_included.php -------------

<?php

//start

class glob

{

   var  $i;

   function glob1()

   {

      include("incl_class.inc");

//      class incl

//      {

//         function incl_test()

//         {

//            return "result!!";

//         }

//      }



      $i=new incl();

      echo $i->incl_test();

   }

};

$g=new glob();

$g->glob1();

?>

//where "incl_class.inc" file contains:

<?php

   class incl

   {

      function incl_test()

      {

         return "result!!";

      }

   }

//end

?>



this example works normal and returns as expected:



     result!!

---- end example(2) -----------



all i'v found in bug lists that similar to my request is  Bug  #11835, 
but  it is different to my question (man try to include content of class,
not the whole class declaration as i'm doing).



Expected result:
----------------
result!!


-- 
Edit bug report at http://bugs.php.net/?id=27344&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=27344&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=27344&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=27344&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=27344&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=27344&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=27344&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=27344&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=27344&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=27344&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=27344&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=27344&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=27344&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27344&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=27344&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=27344&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=27344&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27344&r=float

Reply via email to