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

Description

strlen() calculates the length of a string. It only works on strings, and, in particular, cannot compute the length of the null value.

Example

<?php

$s = null;
print strlen($s);

?>

Solutions

  • Process null in a separate branch of code.

  • Convert null to the empty string before using strlen().