Bug #80103 [NEW]: Passing null to new str_* methods in PHP80 doesn't match documentation

From: Date: Mon, 14 Sep 2020 11:50:30 +0000
Subject: Bug #80103 [NEW]: Passing null to new str_* methods in PHP80 doesn't match documentation
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-17889@lists.php.net to get a copy of this message
From: prose at zedcore dot com Operating system: All PHP version: 8.0.0beta3 Package: Documentation problem Bug Type: Bug Bug description:Passing null to new str_* methods in PHP80 doesn't match documentation Description: ------------ The new str_* functions (str_contains / str_starts_with / str_ends_with) act different than described in the documentation with regards to the type hinting. The documentation says that it should be str_starts_with(string $haystack, string $needle), which would suggest that you wouldn't be allowed to pass null. This isn't the case. This means that the symfony polyfill for PHP80 is unable to polyfill correctly (see https://github.com/symfony/polyfill/issues/282), because either: * We widen the typehint to accept null, which means that the polyfill acts differently in comparison to PHP80 in strict mode when null is passed * We don't widen the typehint, which means that the polyfill acts different in comparison to PHP80 in weak mode when null is passed Test script: --------------- // https://3v4l.org/lSW22V - with strict mode // https://3v4l.org/PQWAG - no strict mode function my_str_starts_with(string $haystack, string $needle): bool { return true; } var_dump(str_starts_with(null, 'abc')); var_dump(my_str_starts_with(null, 'abc')); Expected result: ---------------- In non-strict mode, the script should error when the str_starts_with provided by PHP80 is run. Actual result: -------------- In non-strict mode, null is accepted (and cast to the empty string) -- Edit bug report at https://bugs.php.net/bug.php?id=80103&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=80103&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=80103&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=80103&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=80103&r=needscript Try newer version: https://bugs.php.net/fix.php?id=80103&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=80103&r=support Expected behavior: https://bugs.php.net/fix.php?id=80103&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=80103&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=80103&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=80103&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=80103&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=80103&r=dst IIS Stability: https://bugs.php.net/fix.php?id=80103&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=80103&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=80103&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=80103&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=80103&r=mysqlcfg

« previous php.doc.bugs (#17889) next »