[RndTbl] PHP undefined vars / array indices

Gilbert E. Detillieux gedetil at cs.umanitoba.ca
Wed Jan 19 10:04:50 CST 2022

On 2022-01-19 4:49 a.m., Trevor Cordes wrote:
> On 2022-01-13 Adam Thompson wrote:
>> I don’t really have a horse in this race, but I think John make one
>> factual error.  It’s minor and doesn’t change his point, but:
>> if(!i++) { ... } is perfectly valid in C, where 0==false.  It’s
>> equivalent to (I think…): if(i==0) { i++; ... } else { i++; ... };
>> IIRC, C has the comma operator, albeit thankfully rarely used, so if
>> you really wanted to do this, I think it could be slightly better
>> written: if(i==0, i++) { ... } I could be wrong, I haven’t attempted
>> to write C code in 25+ years.  It’s not something you would want to
>> see, but you certainly could.
> Hey, I use comma all the time! :-)  Well, when it makes sense.  Usually
> in super long perl-oneliners or to get a lot accomplished in one
> expression in a perl regex using /e.
> Perl allows your if(i==0,i++) so I'm nearly positive C would too (Brad,
> paging Brad...).

I'm quite sure C/C++ would allow the comma operator in conditional 
contexts (if/while), but keep in mind that the resulting value is the 
expression to the right of the comma, i.e. i++ in the above example (the 
i==0 would have no net effect).

> The more I seethe about the PHP change, the more I seriously ponder
> making my own fork, or my own "unfixed"-version repo, or trying to get
> a granular logging feature introduced into master project (h/t
> Richard).  The real tell would be if I made a great granular log
> settings patch (like Node, again h/t Richard) and PHP rejected it
> because their real goal is to force their style choices on the world
> (I'd peg that at 50/50 at the moment... or worse).

I'd hold off on making/maintaining your own fork until such a time the 
PHP brain-trust actually raises things from a warning to an error.  In 
the meantime, if you're logging using rsyslog, it would be fairly easy 
to add a one-line filter rule to eliminate the needlessly-noisy warning 
messages.  No more full logs, and no more actual serious warnings 
getting lost like a needle in the haystack!

Gilbert E. Detillieux        E-mail:  <gedetil at cs.umanitoba.ca>
Dept. of Computer Science    Web:     http://cs.umanitoba.ca/~gedetil/
University of Manitoba
Winnipeg MB CANADA  R3T 2N2

More information about the Roundtable mailing list