Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

strpos() With Null Haystack

PHP accepted null as first parameter $string of strpos(). Then, it cast the null to empty string, and returned immediately false, as nothing was found in such string.

Since PHP 8.2, this is a deprecated behavior, with a warning message. It will be removed in PHP 9.

PHP code

<?php

var_dump(strpos(null, '1'));

?>

Before

false

After

strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated

PHP version change

This behavior was deprecated in 8.2.

This behavior changed in 9.0.

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat