Req #68341 [Opn]: reset() & end() could return value of arbitrary expression
Edit report at https://bugs.php.net/bug.php?id=68341&edit=1
ID: 68341
User updated by: bugs dot php dot net at dzubak dot sk
Reported by: bugs dot php dot net at dzubak dot sk
-Summary: reset() & end() to return value for "not variables"
like empty() in PHP 5.5
+Summary: reset() & end() could return value of arbitrary
expression
Status: Open
Type: Feature/Change Request
Package: Arrays related
PHP Version: 5.5.18
Block user comment: N
Private report: N
New Comment:
updated summary, hopefully it will make more sense
Previous Comments:
------------------------------------------------------------------------
[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)