php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #44368 Syntax to index within an expression that evaluates to an array
Submitted: 2008-03-08 06:31 UTC Modified: 2008-03-09 19:31 UTC
From: php at xyzzy dot cjb dot net Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.5 OS: Mac OS X 10.5.2
Private report: No CVE-ID: None
 [2008-03-08 06:31 UTC] php at xyzzy dot cjb dot net
Description:
------------
It would be nice if PHP could allow you to use the [] operator to index 
within an expression that evaluates to an array, as if it was a 
variable.

This feature request is similar to #41268 "Access array member without 
variable", but suggests using the existing [] operator rather than 
adding a new function. I could not find further details on php-internals 
about this issue.

Reproduce code:
---------------
For example:

  $lines = split("\n", $text)
  print $lines[0]

cannot currently be written as

   print split("\n", $text)[0]

nor

   print (split("\n", $text))[0]

Expected result:
----------------
The second and third examples behave identically to the first.

Actual result:
--------------
Parse error: syntax error, unexpected '[' in - on line 2

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-08 21:36 UTC] johannes@php.net
This request was made multiple times before, currently there's no developer having a good fix for that, setting to bogus since it's a known request.
 [2008-03-09 01:11 UTC] php at xyzzy dot cjb dot net
Johannes, can you mark this bug as a duplicate of the known feature 
request, or provide a link to it? Thanks.
 [2008-03-09 19:31 UTC] php at xyzzy dot cjb dot net
http://bugs.php.net/bug.php?id=43577 was closed as "Won't fix" with only  
the message "We discussed this already as well a few times, also not 
going to happen." 

I can't commit there since the bug is closed, but what is the reasoning 
behind not allowing this bug to be fixed? (The bug didn't link to the 
discussion, and I wasn't able to find it.) Does "Won't fix" mean 

a) the developers have no plans to fix this themselves, but will 
consider patches that fix it?

b) or, this change is not desired, and any third-party fixes will be 
rejected?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 14:01:32 2024 UTC