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

From: Date: Tue, 13 Jul 2004 19:42:54 +0000
Subject: #29104 [Opn]: Function declaration in method doesn't work
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-62165@lists.php.net to get a copy of this message
ID: 29104 User updated by: tomas_matousek at hotmail dot com Reported By: tomas_matousek at hotmail dot com Status: Open Bug Type: Zend Engine 2 problem Operating System: WinXP PHP Version: 5.0.0RC3 New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#62165) next »