Page MenuHomePhorge

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

Authored by aklapper on Aug 11 2024, 15:29.

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
Branch
T15911divinerAtomStrlen
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 1513
Build 1513: arc lint + arc unit

Event Timeline

src/applications/diviner/query/DivinerAtomQuery.php
344–346

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