Am 25.01.2022 um 00:47 schrieb Mark Randall <marand...@php.net>:
> ** Undefined Variables Promoted to Error **
> 
> PHP currently treats reading an undefined variable as though it were a null, 
> emitting a warning message in the process. This was previously promoted from 
> a notice in the PHP 8 engine warnings RFC.
> 
> At the time a 3 way vote was held between promoting to an error exception, a 
> warning, or leaving it as a notice.
> 
> At the time, 56% voted in favour of throwing an Error, 28% in favour of a 
> warning, and the remainder leaving it as a notice.
> 
> My understanding is that many of those who voted to raise it to a warning did 
> so because they felt that jumping straight from a notice to an Error was too 
> much in one go.
> 
> As it will have been a warning for around 5 years by the time PHP 9 is 
> released, I expect that there will now be a healthy super majority to bump 
> this up to throwing an error.



I do not think we should make undefined variables (and array indices?) an error:
1) Static analysis has gotten a lot better and catches most of this, often even 
earlier than the runtime check.
2) Hot take: I still consider the well-defined constructs like $count++ or 
$counts[$word]++ to be useful. That's why we actually patch our  PHP to not 
emit warnings for undefined variable or index ...
3) ... which could be impossible at some point once the engine internally makes 
assumptions that the program does not continue after an undefined variable. But 
then again maybe I worry too much :-)

I'll vote 'no' on this one again and would ask you to consider leaving this 
(like many other things) to the realm of static analyzers instead of 
hard-wiring it in the engine, even if you don't use undefined variables 
personally.

Please don't flame me, I just wanted to point out that there is an opposing 
view on internals to consider ;-)

Regards,
- Chris

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to