|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65330 Attaching a variable to an array within the return construct doesn't work
Submitted: 2013-07-25 08:41 UTC Modified: 2013-07-25 13:44 UTC
From: fausten at pw-internet dot de Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.4.17 OS: FreeBSD 9.1
Private report: No CVE-ID: None
 [2013-07-25 08:41 UTC] fausten at pw-internet dot de
If you try within a return construct to attach a variable to an array, the array will be overwriten by the value you tried to attach to it. Because the following examples work, it should also work with test script due to consistency.

$ php -r 'function foo() { $intNumber = 0; return $intNumber + 1 + 2; } var_dump(foo());'

$ php -r 'function bar() { $strText = "foo"; return $strText . "bar"; } var_dump(bar());'
string(6) "foobar"

Test script:
$ php -r 'function foo() { $arrFoo = array(); return $arrFoo[] = "foo"; } var_dump(foo());'

Expected result:
array(1) {
  string(3) "foo"

Actual result:
string(3) "foo"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-25 13:44 UTC]
-Status: Open +Status: Not a bug
 [2013-07-25 13:44 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

I think you should use 

function foo() { $arrFoo = array(); $arrFoo[] = "foo"; return $arrFoo; }

$arrFoo[] = "foo" expression result a "foo" as tmp result... so..
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC