note 126063 added to function.array-pop

From: Date: Sun, 09 May 2021 11:18:52 +0000
Subject: note 126063 added to function.array-pop
Groups: php.notes 
Request: Send a blank email to php-notes+get-216361@lists.php.net to get a copy of this message
Note that array_pop doesn't issue ANY warning or error if the array is already empty when you try to pop something from it. This is bizarre! And it will cause cascades of errors that are hard to resolve without knowing the real cause. Rather than an error, it silently returns a NULL object, it appears, so in my case I ended up with warnings elsewhere about accessing elements of arrays with invalid indexes, as I was expecting to have popped an array. This behaviour (and the lack of any warning, when many trivial things are complained about verbosely) is NOT noted in the manual above. Popping an already empty stack should definitely trigger some sort of notice, to help debugging. Sure, it's probably good practice to wrap the pop in an if (count($array)) but that should be suggested in the manual, if there's no error returned for trying something that should fail and obviously isn't expected to return a meaningful result. ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.242 (proxied: 82.3.80.182) ---- Manual Page -- https://php.net/manual/en/function.array-pop.php Edit -- https://main.php.net/note/edit/126063 Del: integrated -- https://main.php.net/note/delete/126063/integrated Del: useless -- https://main.php.net/note/delete/126063/useless Del: bad code -- https://main.php.net/note/delete/126063/bad+code Del: spam -- https://main.php.net/note/delete/126063/spam Del: non-english -- https://main.php.net/note/delete/126063/non-english Del: in docs -- https://main.php.net/note/delete/126063/in+docs Del: other reasons-- https://main.php.net/note/delete/126063 Reject -- https://main.php.net/note/reject/126063 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#216361) next »