Path: csiph.com!aioe.org!XkYuybOoWlspFRkGYqs4DA.user.46.165.242.91.POSTED!not-for-mail From: Meredith Montgomery Newsgroups: comp.lang.php Subject: Re: php 7.4: null["key"] Date: Tue, 31 May 2022 19:27:22 -0300 Organization: Aioe.org NNTP Server Message-ID: <86r1498hit.fsf@levado.to> References: <86mtfcq6yj.fsf@levado.to> <86ilpnepih.fsf@levado.to> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: gioia.aioe.org; logging-data="8399"; posting-host="XkYuybOoWlspFRkGYqs4DA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org"; Cancel-Lock: sha1:wnr/E0Q+7y3+fKDpLgrHxxkJvTw= X-Notice: Filtered by postfilter v. 0.9.2 Xref: csiph.com comp.lang.php:18963 "J.O. Aho" writes: > On 30/05/2022 04.13, Meredith Montgomery wrote: >> Meredith Montgomery writes: >> >>> I'm upgrading code to PHP 7.4, which will now blow a notice for things >>> such as >>> >>> null["key"] >>> (1.2)["key"] >>> (123)["key"] >>> >>> All of these seem to reduce to null. (The footnote explains why I think >>> so.) >>> >>> I have a lot of code which could be depending on such things. I'd like >>> to rewrite such code, but I have no idea how to find such code. I >>> suppose a loop such as >>> >>> while ($a["key"]) { ... } > > foreach > for > do ... while > > finding all those cases you can use grep (generates a lot of false > positives too): > egrep "(while|for)" -r /path/to/your/scripts Yes. I have millions of lines of code, so I think the best approach is indeed to just go into production with PHP 7.4 and monitor the logs so that we catch the deprecation warnings there --- and then we act. I don't have an army of programmers to analyze each possible loop. I need to be practical here. > This will not take care of cases where someone has assumed they get an > array and then they just need to get something from the array, for > example: > > $var = function_returning_array(); > echo $var[0]; Indeed. [...] >>> How would you search for something like that? I just have no idea. My >>> best idea is to just watch a log of errors and notices and try to spot >>> the code that way. > > There ain't a good way to really find that, unitests had been useful, > just run those and see which ones fail, and then fix the functions > tested. That's what I feared, but that's life. >> I guess nobody had much to say here. I'm tackling easier problems at >> first, but I will eventually have to come back to this and make some >> decision. I suppose upgrading to PHP 7.4 and watching the a noisy log >> with error_reporting = E_ALL (say) might give me more information. But, >> of course, I have no way of running every line of code, so there is >> really no obvious strategy for something like that. > > You could take the time and write unitests now, it will make things > easier next time. One such framework for php is https://phpunit.de > > As you will write tests for each function now, you will locate all the > uses of arrays. That's my next operation. Start writing some important unit tests that were never written. Thank you so much for the phpunit.de recommendation. I checked and see that the project is using SimpleTest instead. I suppose anything reasonable is good enough for us. Thank you for your attention.