php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #41993 [] operator should be first class
Submitted: 2007-07-13 23:09 UTC Modified: 2007-07-14 10:48 UTC
From: jcampbell1 at gmail dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.3 OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jcampbell1 at gmail dot com
New email:
PHP Version: OS:

 

 [2007-07-13 23:09 UTC] jcampbell1 at gmail dot com
Description:
------------
It seems very strange that the [] operator cannot be used on the result of a function.  

Reproduce code:
---------------
function test() {
return array('dog','cat');
}

echo test()[0];  // produces a syntax error.

of course this works fine

class temp{}

function test() {
$o = new $temp;
$temp->foo = 'dog';
}

echo test()->foo; // works


Expected result:
----------------
dog


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-14 10:48 UTC] johannes@php.net
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 has been requested multiple times before, till now nobody came up with a working solution.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 14:01:31 2024 UTC