php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #23168 Variables can be instantiated by first use
Submitted: 2003-04-11 09:37 UTC Modified: 2003-04-15 02:04 UTC
Votes:5
Avg. Score:4.2 ± 1.6
Reproduced:3 of 4 (75.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
From: sascha dot wildgrube at steganos dot com Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 4.3.1 OS: any
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2003-04-11 09:37 UTC] 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!

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-04-11 10:19 UTC] 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 10:29 UTC] 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:57 UTC] jay@php.net
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 
 
 [2003-04-15 02:04 UTC] sascha dot wildgrube at steganos dot com
I didn't want to set up a religious debate! I don't care for how that is solved in Pearl! I know that I can "handle" runtime errors but this kind of errors could be coped with at "build-time". With a more complex script it becomes less likely that this very special condition takes place where the stupid variable name typo comes into play. Do us a favor and add that "VARIABLES MUST BE INSTANCIATED"-option into php. The absence of that option is the main central weakness of php and I don't think it's big time to remove that illness! Thanks!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 23:01:32 2024 UTC