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
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: 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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 30 04:01:30 2024 UTC