ID: 29104
Updated by: [EMAIL PROTECTED]
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:
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.
Previous Comments:
------------------------------------------------------------------------
[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().
------------------------------------------------------------------------
[2004-07-12 09:41:23] tomas_matousek at hotmail dot com
Description:
------------
Declaration of a function in a method doesn't work.
IMHO by declaring a function in a method one creates a function not a
method. It it was a method it would be possible to call it by $a->f().
That works neither.
See the code below:
Reproduce code:
---------------
class A
{
function g()
{
echo "function g - begin\n";
function f()
{
echo "function f\n";
}
echo "function g - end\n";
}
}
$a = new A;
$a->g();
f();
Expected result:
----------------
function g - begin
function g - end
function f
Actual result:
--------------
function g - begin
function g - end
Fatal error: Non-static method A::f() cannot be called statically ...
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=29104&edit=1