#29104 [Opn->Asn]: Function declaration in method doesn't work

From: Date: Sun, 06 Mar 2005 19:39:03 +0000
Subject: #29104 [Opn->Asn]: Function declaration in method doesn't work
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-74954@lists.php.net to get a copy of this message
ID: 29104 Updated by: sniper@php.net Reported By: tomas_matousek at hotmail dot com -Status: Open +Status: Assigned Bug Type: Zend Engine 2 problem Operating System: * -PHP Version: 5.0.0 +PHP Version: 5CVS-2005-03-06 -Assigned To: Andi +Assigned To: andi New Comment: Assigned to the mastah.. Previous Comments: ------------------------------------------------------------------------ [2004-12-30 15:29:19] ulderico at maber dot com dot br OH! In time! Just to reinforce the first and the second paragraph of my last comment. Why would you create a function that should be invoked JUST ONCE? Initialize environment? It makes no point. You can do it directly in the code, using "if" to distinguish any situation of environment that one may have. ------------------------------------------------------------------------ [2004-12-30 15:16:42] ulderico at maber dot com dot br 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? ------------------------------------------------------------------------ [2004-08-14 01:24:12] andrey@php.net 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] helly@php.net PHP does not support nested functions. Still we need to disable this. ------------------------------------------------------------------------ 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

« previous php.bugs (#74954) next »