PHP 8.5.0 Alpha 4 available for testing

Voting

: eight minus one?
(Example: nine)

The Note You're Voting On

webmaster at oehoeboeroe dot nl
16 years ago
You might expect substr('123456', 6) to return an empty string. Instead it returns boolean FALSE.

This behavior should be mentioned in the Return Values section of the manual. Instead it is only mentioned in the Parameters section.

If you need an empty string instead of a boolean FALSE you should typecast the result to a string.

<?php
$a
= substr('123456', 6); // equivalent to $a = FALSE
$a = (string) substr('123456', 6); // equivalent to $a = '';
?>

<< Back to user notes page

To Top