Doc #73132 [Opn->Nab]: mb_substr() doesn't always return a string
| From: | cmb@php.net | Date: | Tue, 20 Sep 2016 21:13:19 +0000 |
| Subject: | Doc #73132 [Opn->Nab]: mb_substr() doesn't always return a string | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-13928@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73132&edit=1
ID: 73132
Updated by: cmb@php.net
Reported by: greg dot bor at franchisedirect dot com
Summary: mb_substr() doesn't always return a string
-Status: Open
+Status: Not a bug
Type: Documentation Problem
Package: Documentation problem
Operating System: irrelevant
PHP Version: Irrelevant
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
The NULL return value is not special to mb_substr(), as the
documentation about internal functions already states[1]:
| If the parameters given to a function are not what it expects,
| such as passing an array where a string is expected, the return
| value of the function is undefined. In this case it will likely
| return NULL but this is just a convention, and cannot be relied
| upon.
[1] <http://php.net/manual/en/functions.internal.php>
Previous Comments:
------------------------------------------------------------------------
[2016-09-20 18:04:58] greg dot bor at franchisedirect dot com
Description:
------------
---
From manual page: http://www.php.net/function.mb-substr
---
"Return Values" says this returns a string, which is true for most cases but not true for
at least one edge case:
var_dump(mb_substr(array(), 0, 1)); returns NULL in PHP 5.3+
(but returns "A" before PHP 5.3).
I haven't checked the PHP source, I guess these it can be determined when exactly does
mb_substr return NULL.
Test results with https://3v4l.org/CuDLX:
Output for 5.3.0 - 5.4.45, 5.5.0 - 5.5.34, 5.5.35 - 5.6.26, hhvm-3.10.0 - 3.14.4, 7.0.0 - 7.1.0RC2
`
Warning: mb_substr() expects parameter 1 to be string, array given in /in/CuDLX on line 3
NULL
`
Output for 4.3.0 - 5.2.17
`
Notice: Array to string conversion in /in/CuDLX on line 3
string(1) "A"
`
Test script:
---------------
var_dump(mb_substr(array(), 0, 1));
Expected result:
----------------
The documentation should define when does mb_substr returns NULL.
Actual result:
--------------
The documentation suggests mb_substr always returns a string.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73132&edit=1