Page MenuHomePhorge

Fix PHP 8.1 "str_replace(null)" exception in DivinerAtomRef
ClosedPublic

Authored by aklapper on Aug 11 2024, 15:29.
Tags
None
Referenced Files
F3676130: D25769.1745539990.diff
Thu, Apr 24, 00:13
F3604857: D25769.1745237133.diff
Sun, Apr 20, 12:05
F3576020: D25769.1745019172.diff
Thu, Apr 17, 23:32
F3552077: D25769.1744903400.diff
Wed, Apr 16, 15:23
F3528965: D25769.1744857199.diff
Wed, Apr 16, 02:33
F3490598: D25769.1744783162.diff
Tue, Apr 15, 05:59
F3390379: D25769.1744466383.diff
Fri, Apr 11, 13:59
F3390350: D25769.1744465997.diff
Fri, Apr 11, 13:53

Details

Summary

Passing null instead of a string or array to str_replace() deprecated since PHP 8.1.

Thus do not create a title array with a null entry in DivinerFindController when there is no $query_text, later to be read via $this->titles in DivinerAtomRef.

ERROR 8192: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated at [/var/www/html/phorge/phorge/src/applications/diviner/atom/DivinerAtomRef.php:205]
  #0 str_replace(string, string, NULL) called at [<phorge>/src/applications/diviner/atom/DivinerAtomRef.php:205]
  #1 DivinerAtomRef::normalizeTitleString(NULL) called at [<phorge>/src/applications/diviner/query/DivinerAtomQuery.php:344]

Credits to valerio.bozzolan for finding the right spot in the code.

Closes T15911

Test Plan

Go to http://phorge.localhost/diviner/find/ (not passing a name URI parameter), optionally with D25768 applied to avoid another exception

Diff Detail

Repository
rP Phorge
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

src/applications/diviner/query/DivinerAtomQuery.php
344–346 ↗(On Diff #2353)

I see that you want to skip the incoming array(null) to fix this:

https://we.phorge.it/source/phorge/browse/master/src/applications/diviner/controller/DivinerFindController.php;66bd13b193b666e77c00ccea0fea508134c5397a$61

But we should probably skip all NULL values, not just the first one.

For example we can do like the old line 360.

In this way:

  • we avoid other unexpected errors when somebody passes an array map without the key 0 (not the case of Phorge, but expected in external calls)
  • we be nice for external calls with array('something', null)
  • also to feel less hacky
This revision now requires changes to proceed.Sep 16 2024, 14:26

Uhhh you found the place where the empty array comes from! <3 I failed!

Confirming that your patch makes http://phorge.localhost/diviner/find/ render results instead of throwing an error. Yay.

Don't create an empty title array when there is no $query_text

aklapper edited the summary of this revision. (Show Details)
This revision is now accepted and ready to land.Sep 16 2024, 20:38