Bug #78635 [NEW]: [Arrow function] In combination with a "substr" call it returns empty string

From: Date: Fri, 04 Oct 2019 20:44:20 +0000
Subject: Bug #78635 [NEW]: [Arrow function] In combination with a "substr" call it returns empty string
Groups: php.standards 
Request: Send a blank email to standards-+get-1459@lists.php.net to get a copy of this message
From: php-0919 at jan-runte dot de Operating system: macOS 10.14.6 PHP version: 7.4.0RC3 Package: PHP Language Specification Bug Type: Bug Bug description:[Arrow function] In combination with a "substr" call it returns empty string Description: ------------ Installation: phpbrew install 7.4.0RC3 +neutral +mbstring To implement the string functions in a generically manner the arrow function is the way we go. The test script demonstrate the misbehavior of the arrow function if it uses "substr". Without the use of arrow function all is fine. By "mb_substr" in the other hand we have no problems. It is not related to the reporting bugs: - Bug #71648: [DE] substr('abc', 3) returns string(0) "" for php7 - Bug #68863: Inconsistent return from substr() The arrow function has the issue. Test script: --------------- <?php { trait StringFunctionMapper { public Closure $substr; protected ?string $encoding = null; public function setSingleByte(): void { $this->encoding = null; $this->substr = fn (string $string, int $start, int $length = null) => substr($string, $start, $length); } public function setMultiByte(string $encoding = 'UTF-8'): void { $this->encoding = $encoding; $this->substr = fn (string $string, int $start, int $length = null) => mb_substr($string, $start, $length, $this->encoding); } } $temp = new class () { use StringFunctionMapper; }; $temp->setSingleByte(); var_dump(substr("search phrase", 6), ($temp->substr)("search phrase", 6)); $temp->setMultiByte(); var_dump(mb_substr("search phrase", 6), ($temp->substr)("search phrase", 6)); } Expected result: ---------------- string(7) " phrase" string(7) " phrase" string(7) " phrase" string(7) " phrase" Actual result: -------------- string(7) " phrase" string(0) "" string(7) " phrase" string(7) " phrase" -- Edit bug report at https://bugs.php.net/bug.php?id=78635&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=78635&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=78635&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=78635&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=78635&r=needscript Try newer version: https://bugs.php.net/fix.php?id=78635&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=78635&r=support Expected behavior: https://bugs.php.net/fix.php?id=78635&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=78635&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=78635&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=78635&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=78635&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=78635&r=dst IIS Stability: https://bugs.php.net/fix.php?id=78635&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=78635&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=78635&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=78635&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=78635&r=mysqlcfg

« previous php.standards (#1459) next »