#23168 [Opn->WFx]: Variables can be instantiated by first use

From: Date: Fri, 11 Apr 2003 15:57:22 +0000
Subject: #23168 [Opn->WFx]: Variables can be instantiated by first use
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-37573@lists.php.net to get a copy of this message
ID: 23168 Updated by: jay@php.net Reported By: sascha dot wildgrube at steganos dot com -Status: Open +Status: Wont fix Bug Type: Feature/Change Request Operating System: any PHP Version: 4.3.1 New Comment: That doesn't raise an error, but it does raise an E_NOTICE. You should be setting your error reporting to E_ALL while you're debugging, and your examples will indeed raise E_NOTICEs telling you about undefined variables. This isn't really any different from Perl (without use strict; of course) and isn't likely to change any time soon. The moral of the story is to use E_ALL when you're writing code. J Previous Comments: ------------------------------------------------------------------------ [2003-04-11 10:29:07] sascha dot wildgrube at steganos dot com it not about error handling. The problem here is that there IS no error. OK in the case of an endless loop there is. But consider this case: $nSumm = 1+2; echo $nSum; What? 1+2 equals "" ???? ------------------------------------------------------------------------ [2003-04-11 10:19:16] michael dot mauch at gmx dot de Put something like this: function myErrorHandler ($errno, $errstr, $errfile, $errline) { die("<p>$errstr in line $errline of $errfile. Dieing now.</p>"); } error_reporting(E_ALL); set_error_handler(myErrorHandler); in an include file, and perhaps use the auto_prepend_file php.ini setting to automagically include it in all your scripts. ------------------------------------------------------------------------ [2003-04-11 09:37:38] sascha dot wildgrube at steganos dot com This is not really a bug. It is a behaviour by design that has troubled php developers for years: The variable-can-be-instantiated-by-first-use-Effect! Just look at that: for ($nIndex=0; $nIndex < 23; $nIndx++) { whatever(); } Most compilers will produce an error like "what the hell is nIndx? Not php. php will produce an endless loop. That is weak! And it is still the number one time eater when programming php. Change that and php as a tool can virtually DOUBLE efficiency! Make the need of variable initialization an option so that the community is not pissed off and existing sources are not rendered useless but for god's sake add it for future use. PLEASE, PLEASE, PLEASE WITH SUGAR, PLEASE WITH SUGAR AND CREAM!!!! Thanks! ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=23168&edit=1

« previous php.bugs (#37573) next »