ID: 27344 Updated by: [EMAIL PROTECTED] Reported By: fox000 at yandex dot ru -Status: Open +Status: Bogus Bug Type: Scripting Engine problem Operating System: windows XP PHP Version: 4.3.4 New Comment:
Not bug. included code is compiled separately. Previous Comments: ------------------------------------------------------------------------ [2004-02-22 02:03:58] 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!! ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=27344&edit=1