Page MenuHomePhabricator

Phabricator global search: "Cannot use object of type PhutilSafeHTML as array" error for certain strings
Closed, ResolvedPublic

Description

When searching for certain strings in Phabricator there is an exception:

Unhandled Exception ("Error")
Cannot use object of type PhutilSafeHTML as array

Interestingly there are a few patterns that seem to trigger it while others don't. For example:

stringresult
foook
mw1234ok
mw2234error
mw222ok
mw2222error
xx2234ok
xxmw2234ok
mw2234xok
mw2261error
mw2261xok
cloudvirt1001error

The ones that are errors are repeatable and don't seem random. It seems more like the error happens if it actually finds some results?

Event Timeline

Aklapper renamed this task from Phabricator search - Cannot use object of type PhutilSafeHTML as array to Phabricator global search: "Cannot use object of type PhutilSafeHTML as array" error for certain strings.Sep 17 2020, 1:23 PM

Luckily searching for "Cannot use object of type PhutilSafeHTML as array" works :)

I think it must be some procurement task that you all can see but I can't.

When i go to advanced search and use the same string but just additionally limit it to "Document Type: Task" the the issue is gone. So it's like it's something that is not type task.

Ok this one has got to be one of the biggest WATPHP bugs I've ever had to deal with.

So PHP supports treating strings like an array, to access single characters like

$char = $str[$i]

But, phabricator builds output using PhutilSafeHTML objects which wrap strings and ensure that everything gets encoded properly. Whenever you try to do string manipulation on one of those objects, the __toString() method converts it to an actual string. This has always worked just fine until now. For some reason PHP decided that str[$i] in this one particular context is an array dereference instead of a string index, so it threw an exception instead of calling the toString method on the PhitilSafeHTML object. Fixed with an explicit cast to string
here:

$str = (string) $str;

Mentioned in SAL (#wikimedia-operations) [2020-09-18T09:47:46Z] <twentyafterfour> deployed hotfix for T263063 to phab1001

see above for wtf php lol

Glorious.

mmodell claimed this task.

This is a one-liner downstream patch we've been carrying around for three years which has not been upstreamed yet.

Should it be upstreamed? Or not? I cannot reproduce locally (PHP 8.2) or in Phorge upstream though.

Should it be upstreamed? Or not? I cannot reproduce locally (PHP 8.2) or in Phorge upstream though.

Since upstream is now Phorge and you can't reproduce in Phorge, i guess not.