php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41242 Array values destroyed after using as reference in function call
Submitted: 2007-04-30 16:04 UTC Modified: 2007-04-30 17:15 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: laurynas at by dot lt Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.2.1 OS: Linux 2.6.17.7
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: laurynas at by dot lt
New email:
PHP Version: OS:

 

 [2007-04-30 16:04 UTC] laurynas at by dot lt
Description:
------------
Array values are destroyed after using it as reference in function call defining in call dirrectly as array. If given array is constructed before function call in the same parameters line, PHP returns nothing, but really shoud return a value associated to array.

Reproduce code:
---------------
<?php
	// this is our defined function
	// as you can see the second parameter is reference
	function someFunc($param1, & $array) {
		// so expecting $array as array we
		// put some value in it
		$array[0] = 'some value';
	}
	
	// now call the function, please note, that array $user
	// is created as array type *outside* function
	someFunc(null, $user = array());
	
	// now let's check returned value
	print_r($user);
?>

Expected result:
----------------
Array
(
    [0] => some value
)

Actual result:
--------------
Array
(
)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-04-30 16:06 UTC] tony2001@php.net
"$user = array()" is not a variable, but an expression.
 [2007-04-30 16:13 UTC] laurynas at by dot lt
Agree, this is expresion, but the expression is executed before function is called, right? So the variable should be defined *before* function takes variable as a parameter. Then why it works in PHP 4.x?
 [2007-04-30 16:52 UTC] johannes@php.net
No, the behavior is undefined (and currently executed after the function call - but that doesn't make it defined - might change anytime) 
 [2007-04-30 17:15 UTC] laurynas at by dot lt
Logicaly, this should be fixed or defined anyway, because this is quite often situation by many developers.

C/C# syntax executes these expressions *before* function call.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 16:01:28 2024 UTC