php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27344 mindless in classes declaration ( class included in other class)
Submitted: 2004-02-22 02:03 UTC Modified: 2004-02-22 22:45 UTC
Votes:1
Avg. Score:2.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: fox000 at yandex dot ru Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.3.4 OS: windows XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: fox000 at yandex dot ru
New email:
PHP Version: OS:

 

 [2004-02-22 02:03 UTC] fox000 at yandex dot ru
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!!


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-22 22:45 UTC] sniper@php.net
Not bug. included code is compiled separately.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Sep 12 08:01:27 2024 UTC