Req #68341 [NEW]: reset() & end() to return value for "not variables" like empty() in PHP 5.5

From: Date: Tue, 04 Nov 2014 10:23:00 +0000
Subject: Req #68341 [NEW]: reset() & end() to return value for "not variables" like empty() in PHP 5.5
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-188438@lists.php.net to get a copy of this message
From:             bugs dot php dot net at dzubak dot sk
Operating system: 
PHP version:      5.5.18
Package:          Arrays related
Bug Type:         Feature/Change Request
Bug description:reset() & end() to return value for "not variables" like empty() in
PHP 5.5

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 bug report at https://bugs.php.net/bug.php?id=68341&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=68341&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=68341&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=68341&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=68341&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=68341&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=68341&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=68341&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=68341&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=68341&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=68341&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=68341&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=68341&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=68341&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68341&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=68341&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=68341&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=68341&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68341&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=68341&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=68341&r=mysqlcfg



Thread (4 messages)

« previous php.bugs (#188438) next »