php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #11063 $var = function_returning_array(args)[0]; doesn't work
Submitted: 2001-05-23 16:35 UTC Modified: 2012-04-11 12:08 UTC
From: jeremy at deadbeef dot com Assigned: nikic (profile)
Status: Closed Package: *General Issues
PHP Version: 4.0.4pl1 OS: Windows NT 4.0 Build 1381
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jeremy at deadbeef dot com
New email:
PHP Version: OS:

 

 [2001-05-23 16:35 UTC] jeremy at deadbeef dot com
$var = function_returning_array(args)[0];

gives an error but 

$var = function_returning_array(args);
$var=$var[0];

works fine.  I think that either should work.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-05-23 17:33 UTC] derick@php.net
This syntax does not make sense at all (to me). It is not present in any language AFAIK.
A function simply returns an array, and if you want to do something with that, do it later.

However, it is a valid feature request, but I don't think it wil be implemented in short time.
Changed type to Feature Request and status to Suspended.

Derick
 [2001-05-23 17:37 UTC] jeremy at deadbeef dot com
I think that $var=(function_returning_array(args))[0]; should also work, but it does not either.

The real problem here is that the [] operator works only on variables, not on general expressions. 

Just trying to make php more c-like in it's expression syntax.
 [2012-04-11 12:08 UTC] nikic@php.net
Closing as this was implemented in PHP 5.4.
 [2012-04-11 12:08 UTC] nikic@php.net
-Status: Suspended +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: nikic
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Mar 12 11:01:32 2025 UTC