Bug #17055 Updated: Must declare function before referencing when in the scope of an if statement

From: Date: Tue, 07 May 2002 06:52:18 +0000
Subject: Bug #17055 Updated: Must declare function before referencing when in the scope of an if statement
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-7119@lists.php.net to get a copy of this message
ID: 17055 Updated by: derick@php.net Reported By: spamsucks86@comcast.net -Status: Open +Status: Suspended -Bug Type: Scripting Engine problem +Bug Type: Feature/Change Request -Operating System: Windows 2000 Pro +Operating System: All PHP Version: 4.1.2 New Comment: This is not really a bug, as PHP only 'remembers' functions as soon as they are seen by the compiler. Because the compiler does not know if this specific branch will be executed, it doesn't add the function to the function table immediately, but waits until it actually 'hits' the function declaration. Therefore the function will nto be defined at the locate where you get your error. The only way to prevent this is to move out the function declaration out of the branch and in the main scope of the script. Then it doesn't matter if you define it before or after the call to the function. I'm making this report a suspended function/request, as I don't see any fast implementation of this. Derick Previous Comments: ------------------------------------------------------------------------ [2002-05-06 19:38:03] spamsucks86@comcast.net if (1==1) { if (1==2) { echo 'blah'; } else { test('test'); } <--RIGHT HERE function test ($blah) { echo $blah; } } This script gives the error: Fatal error: Call to undefined function: test() <line 6>. PHP should have recognized that since the first if statement was true, all functions in the scope of that if statement should be declared. If I move the function declaration to before I use it, it works. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=17055&edit=1

« previous php.bugs (#7119) next »