php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #68341 reset() & end() could return value of arbitrary expression
Submitted: 2014-11-04 10:22 UTC Modified: 2014-11-06 08:12 UTC
Votes:2
Avg. Score:3.0 ± 2.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: bugs dot php dot net at dzubak dot sk Assigned:
Status: Open Package: Arrays related
PHP Version: 5.5.18 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2014-11-04 10:22 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-11-05 09:26 UTC] 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
 [2014-11-05 09:26 UTC] bugs dot php dot net at dzubak dot sk
updated summary, hopefully it will make more sense
 [2014-11-06 08:12 UTC] 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.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Jun 25 00:01:26 2019 UTC