Bug #75824 [NEW]: Inconsistent handling of void/null optional return type hints

From: Date: Tue, 16 Jan 2018 15:14:50 +0000
Subject: Bug #75824 [NEW]: Inconsistent handling of void/null optional return type hints
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213561@lists.php.net to get a copy of this message
From: adam at nostradamus dot nu Operating system: any PHP version: 7.1.13 Package: Scripting Engine problem Bug Type: Bug Bug description:Inconsistent handling of void/null optional return type hints Description: ------------ We are running into an issue where a function that does not return any value fails in strict mode when an optional return type hint is applied. Observe the following php scripts: https://3v4l.org/o5ufU https://3v4l.org/5TIB5 (the only difference is the explicit null return in the second one) In my opinion, the first one should succeed as well, specifically since the strict check in the following script succeeds: https://3v4l.org/hn6F0 Expected result: ---------------- NULL int(1) Actual result: -------------- Fatal error: Uncaught TypeError: Return value of Foo::getTest() must be of the type integer or null, none returned in /in/o5ufU:10 Stack trace: #0 /in/o5ufU(15): Foo->getTest() #1 {main} thrown in /in/o5ufU on line 10 Process exited with code 255. -- Edit bug report at https://bugs.php.net/bug.php?id=75824&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75824&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75824&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75824&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=75824&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=75824&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=75824&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=75824&r=needscript Try newer version: https://bugs.php.net/fix.php?id=75824&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=75824&r=support Expected behavior: https://bugs.php.net/fix.php?id=75824&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=75824&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=75824&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=75824&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75824&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=75824&r=dst IIS Stability: https://bugs.php.net/fix.php?id=75824&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=75824&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=75824&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=75824&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=75824&r=mysqlcfg

« previous php.bugs (#213561) next »