php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43768 Using [] operator on an array returned by a function call throws fatal error
Submitted: 2008-01-06 15:10 UTC Modified: 2008-01-06 19:37 UTC
From: roan dot kattouw at home dot nl Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.5 OS: any
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: roan dot kattouw at home dot nl
New email:
PHP Version: OS:

 

 [2008-01-06 15:10 UTC] roan dot kattouw at home dot nl
Description:
------------
Any construct of the form myFunc()[x] or $object->myFunc()[x] results in a fatal error, even if myFunc() returns an array. Putting the expression in parentheses (like (myFunc())[x]) doesn't help. The only remedy seems to be using an intermediate variable.

Reproduce code:
---------------
<?php
function getArray() { return array(1, 2, 3); }

echo getArray()[1];
?>

Expected result:
----------------
"2" being output

Actual result:
--------------
Parse error: syntax error, unexpected '[', expecting ',' or ';' in test.php on line 4

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-06 19:37 UTC] felipe@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

See http://bugs.php.net/bug.php?id=43577
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Dec 12 01:00:01 2025 UTC