Req #79662 [NEW]: substr($string, $offset, null) should return from $offset till end

From: Date: Mon, 01 Jun 2020 20:41:37 +0000
Subject: Req #79662 [NEW]: substr($string, $offset, null) should return from $offset till end
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-227266@lists.php.net to get a copy of this message
From: thflori at gmail dot com Operating system: Linux/Any PHP version: 7.4.6 Package: Strings related Bug Type: Feature/Change Request Bug description:substr($string, $offset, null) should return from $offset till end 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 bug report at https://bugs.php.net/bug.php?id=79662&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=79662&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=79662&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=79662&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=79662&r=needscript Try newer version: https://bugs.php.net/fix.php?id=79662&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=79662&r=support Expected behavior: https://bugs.php.net/fix.php?id=79662&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=79662&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=79662&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=79662&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=79662&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=79662&r=dst IIS Stability: https://bugs.php.net/fix.php?id=79662&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=79662&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=79662&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=79662&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=79662&r=mysqlcfg

« previous php.bugs (#227266) next »