ID:          50617
 Updated by:  j...@php.net
 Reported By: billyellison99 at gmail dot com
-Status:      Open
+Status:      Bogus
 Bug Type:    Feature/Change Request
 PHP Version: 5.3.2RC1
 New Comment:

Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

This is a duplicate of http://bugs.php.net/bug.php?id=23022


Previous Comments:
------------------------------------------------------------------------

[2009-12-31 05:59:17] jrhodes at roket-enterprises dot com

I second this feature request.

Function Array Dereferencing allows programmers to write cleaner code 
and is adopted by many other programming languages such as Ruby and 
Python.  Adding this feature doesn't break any previous code written 
in PHP.

Examples:
============
With FAD:
----
$var = func()[2];

Without FAD: (Current PHP)
----
$var = func();
$var = $var[2];
OR
$var = func();
$othervar = $var[2];
unset($var);

With FAD:
----
otherfunc(func()[2]);

Without FAD:
----
$var = func();
otherfunc($var[2]);
unset($var);

------------------------------------------------------------------------

[2009-12-31 05:16:57] billyellison99 at gmail dot com

Description:
------------
In Perl, I am able to do something like:
print (explode(",", $myString))[1];

which would print the second result of explode (which returns an 
array). Sadly, this feature is lacking in PHP. I'd really like to see 
this in PHP, because it adds so much convenience to coding, and 
shortens it, rather than having to assign to a variable, then obtaining

the value from the variable.

Reproduce code:
---------------
<?php
$myString = "The,quick,brown,fox";
$secondpart = (explode(",", $myString))[1];
echo $secondpart;
?>

Expected result:
----------------
quick

Actual result:
--------------
Parse error: syntax error, unexpected '[' in 
/home/billy/Desktop/index.php on line 3


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=50617&edit=1

Reply via email to