Bug #74509 [NEW]: array_shift($foo) throws "null given" instead of "Undefined variable"

From: Date: Fri, 28 Apr 2017 16:15:13 +0000
Subject: Bug #74509 [NEW]: array_shift($foo) throws "null given" instead of "Undefined variable"
Groups: php.standards 
Request: Send a blank email to standards-+get-1265@lists.php.net to get a copy of this message
From: pov at fingerprint dot fr Operating system: PHP version: 5.6.30 Package: PHP Language Specification Bug Type: Bug Bug description:array_shift($foo) throws "null given" instead of "Undefined variable" Description: ------------ When applying array_shift on a non-existing variable, a warning about array_shift is emitted (array_shift() expects parameter 1 to be array, null given) instead of a notice on the non-existing variable. Tested on all the following packaged versions : 7.0.17-2+deb.sury.org~trusty+1 7.1.3-2+deb.sury.org~trusty+1 5.5.38-4+deb.sury.org~trusty+1 5.6.30-7+deb.sury.org~trusty+1 -- Additional tests This bug probably applies on other functions as well. Some tests gives interesting results (I note NUV = Notice : Undefined variable - ok -, WNG = Warning : null given - which shouldn't be) : array_shift($foo) WNG array_slice($foo) NUV array_unshift($foo, 1) WNG array_unshift($foo, $bar) NUV bar (logically, should be NUV $foo first) array_pop($foo) WNG array_sum($foo) NUV empty($foo) returns true htmlentities($foo) NUV Test script: --------------- error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', true); echo '$foo = '; echo $foo; echo "\n"; echo 'array_shift($foo) = '; echo array_shift($foo); echo "\n"; exit; Expected result: ---------------- $foo = Notice: Undefined variable: foo in index.php on line 4 array_shift($foo) = Notice: Undefined variable: foo in index.php on line 4 Actual result: -------------- $foo = Notice: Undefined variable: foo in index.php on line 4 array_shift($foo) = Warning: array_shift() expects parameter 1 to be array, null given in index.php on line 5 -- Edit bug report at https://bugs.php.net/bug.php?id=74509&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74509&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74509&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74509&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=74509&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=74509&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=74509&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=74509&r=needscript Try newer version: https://bugs.php.net/fix.php?id=74509&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=74509&r=support Expected behavior: https://bugs.php.net/fix.php?id=74509&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=74509&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=74509&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=74509&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74509&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=74509&r=dst IIS Stability: https://bugs.php.net/fix.php?id=74509&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=74509&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=74509&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=74509&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=74509&r=mysqlcfg

« previous php.standards (#1265) next »