Using Drupal on PHP 8.1, the module throws this warning.

Deprecated function: stristr(): Passing null to parameter #1 ($haystack) of type string is deprecated in Drupal\amp\Service\AMPService::isDevPage() (line 173 of modules/contrib/amp/src/Service/AMPService.php).

That happens because AMPService::isDevPage() calls \Drupal::request()->getQueryString() and passes the values it return to stristr(), which doesn't accept anymore a NULL value, on PHP 8.1.

Before calling stristr(), the code needs to check the passed argument isn't NULL or cast that value to a string. In this way, NULL will be converted to an empty string.

CommentFileSizeAuthor
amp-stristr-warning-patch.diff596 bytescasivaagustin

Comments

casivaagustin created an issue. See original summary.

avpaderno’s picture

Title: Deprecated function: stristr(): Passing null to parameter #1 ($haystack) of type string is deprecated in Drupal\amp\Service\AMPService->isDevPage() » stristr(): Passing null to parameter #1 ($haystack) of type string is deprecated in Drupal\amp\Service\AMPService::isDevPage()
Priority: Minor » Normal
Issue tags: +PHP 8.1
avpaderno’s picture

Issue summary: View changes
avpaderno’s picture

Status: Active » Needs review
ankitjhakal’s picture

Assigned: Unassigned » ankitjhakal
ankitjhakal’s picture

Assigned: ankitjhakal » Unassigned
Status: Needs review » Reviewed & tested by the community

Tested and applied patch on local. Issue is resolved after applying patch. So changing status of it.

berdir’s picture

Duplicate of #3263406: stristr(): Passing null to parameter #1 ($haystack) of type string is deprecated in Drupal\amp\Service\AMPService::isDevPage()

The other patch has strange formatting though, so maybe makes more sense to commit this.

pick_d’s picture

Patch works for me as well (Drupal 9.5.1, PHP 8.1.13).

Thanks a lot.

littlepixiez’s picture

Patch works for me! Fixes deprecation errors on PHP 8.1. Thanks @casivaagustin

phjou’s picture

Patch works for me as well, it would be great to be merged, thank you.

e0ipso’s picture

I just created (then closed) a duplicate of this #3356049: stristr(): Passing null to parameter #1 ($haystack) of type string is deprecated in AMPService::isDevPage(). I am facing this issue as well.

m4olivei’s picture

Status: Reviewed & tested by the community » Fixed

Thanks everyone!

Committed to 8.x-3.x. I'll tag a release shortly.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.