#29104 [Asn->Csd]: Function declaration in method doesn't work
| From: | dmitry@php.net | Date: | Wed, 27 Apr 2005 13:31:19 +0000 |
| Subject: | #29104 [Asn->Csd]: Function declaration in method doesn't work | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-78296@lists.php.net to get a copy of this message | ||
ID: 29104
Updated by: dmitry@php.net
Reported By: tomas_matousek at hotmail dot com
-Status: Assigned
+Status: Closed
Bug Type: Zend Engine 2 problem
Operating System: *
PHP Version: 5CVS-2005-03-06
Assigned To: andi
New Comment:
Fixed in CVS HEAD and PHP_5_0.
Previous Comments:
------------------------------------------------------------------------
[2005-03-25 15:14:21] php at trancer dot nl
Mind you that such code _IS_ working PHP4 so it is breaking BC and not
listed on http://www.zend.com/manual/migration5.incompatible.php
As to why it could be useful.. to do recursion and not register a
function in global scope. (Of course there are methods for this
aswell.)
------------------------------------------------------------------------
[2005-03-06 20:39:03] sniper@php.net
Assigned to the mastah..
------------------------------------------------------------------------
[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.
------------------------------------------------------------------------
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