php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63712 function returning array and directly calling array element parse error
Submitted: 2012-12-06 15:13 UTC Modified: 2012-12-06 17:47 UTC
From: tretoria at data dot bg Assigned: nikic (profile)
Status: Closed Package: Compile Failure
PHP Version: 5.3.19 OS: win32
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: tretoria at data dot bg
New email:
PHP Version: OS:

 

 [2012-12-06 15:13 UTC] tretoria at data dot bg
Description:
------------
When calling function which returns array and try to get element of the returned array directly, without copying the result into variable like "foo()[x]" where x is integer, it returns parse syntax error.
However this is working in 5.4.* versions.

Test script:
---------------
<?php
	function returnArray()
	{
		$arr = array("first", "second", "third");

		return $arr;
	}

	echo returnArray()[1];
?>

Expected result:
----------------
second

Actual result:
--------------
Parse error: syntax error, unexpected '[', expecting ',' or ';'

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-06 17:47 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2012-12-06 17:47 UTC] nikic@php.net
This feature was added in PHP 5.4.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon May 05 21:01:29 2025 UTC