Page MenuHomePhabricator

Re-evaluate usage of ord() vs other functions like str_starts_with
Open, Needs TriagePublic

Event Timeline

I would hope that the str_starts_with -> ord optimization does not exist anywhere else. It's a sin I explicitly came up with for that code in ApiResult and I hope it hasn't spread. In most (if not all) cases, the actionable should be to add an explicit [0] to get the first character or something like that.

I would hope that the str_starts_with -> ord optimization does not exist anywhere else. It's a sin I explicitly came up with for that code in ApiResult and I hope it hasn't spread. In most (if not all) cases, the actionable should be to add an explicit [0] to get the first character or something like that.

See some of the referenced tasks.. There's been a few cases where we've needed to swap to [0] and also checking it's not an empty string either in the first place as necessary starting in PHP 8.5.

Yep I saw those, if anything to find out whether my horrible hack had propagated, and so far it looks like it hasn't. I guess my point above is that str_starts_with should never be a replacement (except for ApiResult), and that [0] access (possibly with empty string check or null coalesce) should typically suffice.