Req #79662 [Opn->Csd]: substr($string, $offset, null) should return from $offset till end
| From: | nikic@php.net | Date: | Mon, 01 Jun 2020 20:44:00 +0000 |
| Subject: | Req #79662 [Opn->Csd]: substr($string, $offset, null) should return from $offset till end | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-227267@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79662&edit=1
ID: 79662
Updated by: nikic@php.net
Reported by: thflori at gmail dot com
Summary: substr($string, $offset, null) should return from
$offset till end
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: Strings related
Operating System: Linux/Any
PHP Version: 7.4.6
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
This has already been addressed in PHP 8. As this is part of a large set of default value handling
improvements, and is technically backwards compatibility breaking, I don't think we want to
backport this to earlier versions.
Previous Comments:
------------------------------------------------------------------------
[2020-06-01 20:41:37] thflori at gmail dot com
Description:
------------
Usually when you don't want to pass an optional argument you pass null. That does not only feel
natural for me I hope. But not with substr - when you pass null it is the same as when you pass 0.
It is clearly described in the documentation as well.
This looks like no problem for the most of the users. Obviously just don't pass it. But no one
knows what the developers out there might develop; maybe the third parameter comes from another call
and you have to write an exception for substr:
<?php
if ($length === null)
$sub = substr($string, $offset);
else
$sub = substr($string, $offset, $length);
I'm not sure is it really intended to be that way or are there only historical reasons?
---
From manual page: https://php.net/function.substr
---
Test script:
---------------
<?php
$string = 'lorem ipsum';
$passNull = substr($string, 6, null);
var_dump($passNull);
Expected result:
----------------
string(5) "ipsum"
Actual result:
--------------
string(0) ""
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79662&edit=1