Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #18964
| From | De ongekruisigde <ongekruisigde@news.eternal-september.org> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: php 7.4: null["key"] |
| Date | 2022-05-31 22:39 +0000 |
| Organization | Ongekruisigden |
| Message-ID | <t765ep$77k$1@dont-email.me> (permalink) |
| References | <86mtfcq6yj.fsf@levado.to> <86ilpnepih.fsf@levado.to> <jfj569Foau1U1@mid.individual.net> <86r1498hit.fsf@levado.to> |
On 2022-05-31, Meredith Montgomery <mmontgomery@levado.to> wrote:
> "J.O. Aho" <user@example.net> writes:
>
>> On 30/05/2022 04.13, Meredith Montgomery wrote:
>>> Meredith Montgomery <mmontgomery@levado.to> 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.
Have you looked at PHPCompatibility?
<https://github.com/PHPCompatibility/PHPCompatibility>
--
"Though a program be but three lines long, someday it will have to be
maintained." [The Tao of Programming]
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
php 7.4: null["key"] Meredith Montgomery <mmontgomery@levado.to> - 2022-05-20 17:34 -0300
Re: php 7.4: null["key"] Meredith Montgomery <mmontgomery@levado.to> - 2022-05-29 23:13 -0300
Re: php 7.4: null["key"] "J.O. Aho" <user@example.net> - 2022-05-30 08:06 +0200
Re: php 7.4: null["key"] Meredith Montgomery <mmontgomery@levado.to> - 2022-05-31 19:27 -0300
Re: php 7.4: null["key"] De ongekruisigde <ongekruisigde@news.eternal-september.org> - 2022-05-31 22:39 +0000
Re: php 7.4: null["key"] Meredith Montgomery <mmontgomery@levado.to> - 2022-06-02 17:26 -0300
Re: php 7.4: null["key"] Meredith Montgomery <mmontgomery@levado.to> - 2022-06-03 17:09 -0300
Re: php 7.4: null["key"] De ongekruisigde <ongekruisigde@news.eternal-september.org> - 2022-06-04 14:35 +0000
csiph-web