Req #68341 [Opn->Csd]: reset() & end() could return value of arbitrary expression
Edit report at https://bugs.php.net/bug.php?id=68341&edit=1
ID: 68341
Updated by: cmb@php.net
Reported by: bugs dot php dot net at dzubak dot sk
Summary: reset() & end() could return value of arbitrary
expression
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: Arrays related
PHP Version: 5.5.18
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
As of PHP 7.3.0, the functions array_key_first() and
array_key_last() are available, which you can use instead.
Previous Comments:
------------------------------------------------------------------------
[2014-11-06 08:12:52] bugs dot php dot net at dzubak dot sk
I made mistake in this sentence:
I can simply add [0] to end of variable or function to get value of **FIRST** element.
------------------------------------------------------------------------
[2014-11-05 09:26:05] bugs dot php dot net at dzubak dot sk
updated summary, hopefully it will make more sense
------------------------------------------------------------------------
[2014-11-04 10:22:59] bugs dot php dot net at dzubak dot sk
Description:
------------
Since PHP 5.5 empty() supports arbitrary expressions, could PHP do same with reset() and end()?
I can simply add [0] to end of variable or function to get value of last element. However this
approach does not work when I use arbitrary or non-integer keys. It is even more tricky when I want
"just get last value" of array.
Expected result:
----------------
I would welcome to be able to get first and last value of "any kind of array" like this:
reset(someFunction()); # returns value of first element
end(explode('/', '/very/long/path/to/filename.txt')); # returns filename without
path (value of last element of explode())
Actual result:
--------------
end([]); # Fatal error: Only variables can be passed by reference
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68341&edit=1
Thread (4 messages)