ID: 29104 Comment by: ulderico at maber dot com dot br Reported By: tomas_matousek at hotmail dot com Status: Open Bug Type: Zend Engine 2 problem Operating System: * PHP Version: 5.0.0 Assigned To: Andi New Comment:
IMHO, Nested Functions are BAD&WRONG, thus they should be disabled. Firstly, when you DECLARE a function inside a function, you have a redeclaration problem. Try to execute the parent function twice and most likely you'll receive a message: "Fatal error: Cannot redeclare XXXX". OK! Some may dispute: "let's create an undeclare_function() so as to allow at the end of the function undeclare the child function. It would enable to reinvoke the parent function whenever we like". Well, THIS IS ALSO B&R. Why would you undeclare a function that you're going to use? Secondly, if a function needs to work in a closed (encapsuled) environment, well, I think you need a CLASS, not a function. In a class you may have a public, private or protected variables invoked by either public, private or protected methods. Thusly, a code like this (sorry the indentation, I want to save space): class A { function b(){} function c(){} function d(){} function g(){ echo "function g - begin\n"; function f(){echo "function f\n";} echo "function g - end\n"; } } should be written like this: class A { function b(){} function c(){} function d(){} function g(){ echo "function g - begin\n"; f::f(); echo "function g - end\n"; } } class f{ function f(){echo "function f\n";} } $obj = new A(); $obj->g(); So, the rationale is, why you need to have function within function if you've got classes? Previous Comments: ------------------------------------------------------------------------ [2004-08-14 01:24:12] [EMAIL PROTECTED] While nested functions are maybe useful feature for someone declaration of a function inside the body of a method (which happens to be a function inside a class) is _ambigious_ . Why? There is no reserved word "method" for marking methods of a class and "function" is used so when it is between {} after class name "function" creates a method of the class. IMO "function" inside a method should not be possible. ------------------------------------------------------------------------ [2004-07-16 18:00:35] postings-php-bug at hans-spath dot de Wait a minute, PHP doesn't support nested functions? Holy shit, documentation lies! http://www.php.net/manual/en/language.functions.php "Example 12-3. Functions within functions" Do we need to file a documentation bug, too? ------------------------------------------------------------------------ [2004-07-13 21:46:59] [EMAIL PROTECTED] PHP does not support nested functions. Still we need to disable this. ------------------------------------------------------------------------ [2004-07-13 21:42:52] tomas_matousek at hotmail dot com PHP supports declaring functions "inline", i.e. almost anywhere in a code. Such function is declared as global wherever it is declared. Hence, I don't see any ambiguity if a function is declared inside a method. PHP doesn't support adding new methods into existing class. That's why a function declared in method can only be a global one. ------------------------------------------------------------------------ [2004-07-13 17:45:57] Jason at hybd dot net >From what I gather, like most languages, PHP doesn't support 'nested' methods. (And therefore I doubt this is a bug) Where you are calling f() is ambigous. As far as PHP is concerned f() is probably a global function and not a method embedded inside a::g(). ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/29104 -- Edit this bug report at http://bugs.php.net/?id=29104&edit=1