Edit report at https://bugs.php.net/bug.php?id=65330&edit=1

 ID:                 65330
 Updated by:         larue...@php.net
 Reported by:        fausten at pw-internet dot de
 Summary:            Attaching a variable to an array within the return
                     construct doesn't work
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Arrays related
 Operating System:   FreeBSD 9.1
 PHP Version:        5.4.17
 Block user comment: N
 Private report:     N

 New Comment:

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

I think you should use 

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

$arrFoo[] = "foo" expression result a "foo" as tmp result... so..


Previous Comments:
------------------------------------------------------------------------
[2013-07-25 08:41:04] fausten at pw-internet dot de

Description:
------------
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());'
int(3)

$ 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) {
  [0]=>
  string(3) "foo"
}

Actual result:
--------------
string(3) "foo"


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=65330&edit=1

Reply via email to