php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35905 References don't work in some cases starting from PHP 5.1.1
Submitted: 2006-01-05 14:31 UTC Modified: 2006-01-09 10:30 UTC
From: benadin at ukr dot net Assigned: dmitry (profile)
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.1.1 OS: FreeBSD 5.4
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: benadin at ukr dot net
New email:
PHP Version: OS:

 

 [2006-01-05 14:31 UTC] benadin at ukr dot net
Description:
------------
In the code below method StructAddNodePointer gets a part (branch) of the array (in the example $bar->dxml_struct_arr) and fills it. It works in PHP 5.0.5 but doesn't work in PHP 5.1.1. It seems in PHP 5.1.1 passing &$dxml_struct_arr by reference doesn't work. Or may be it doesn't work here: $pointer_tree_doc_value = &$bar->StructAddNodePointer('doc', $bar->dxml_struct_arr);

Reproduce code:
---------------
class foo {
	function StructAddNode($tag, &$dxml_struct_arr, $attribs = array()) {
		$dxml_struct_arr[] = array(
			'tag' => $tag,
			'value' => null #array()
		);
		$index= (sizeof($dxml_struct_arr)-1);
		return $index;
	}
	function StructAddNodePointer($tag, &$dxml_struct_arr, $attribs = array()) {
		$index = $this->StructAddNode($tag, $dxml_struct_arr, $attribs);
		return $dxml_struct_arr[$index]['value'];
	}
}
$bar = new foo();
$bar->dxml_struct_arr = array();
$pointer_tree_doc_value = &$bar->StructAddNodePointer('doc', $bar->dxml_struct_arr);
$pointer_tree_head_value = &$bar->StructAddNodePointer('HEAD', $pointer_tree_doc_value);
print_r($bar->dxml_struct_arr);

Expected result:
----------------
Array
(
    [0] => Array
        (
            [tag] => doc
            [value] => Array
                (
                    [0] => Array
                        (
                            [tag] => HEAD
                            [value] => 
                        )

                )

        )

)


Actual result:
--------------
Array
(
    [0] => Array
        (
            [tag] => doc
            [value] => 
        )

)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-01-06 01:52 UTC] tony2001@php.net
I get the same (i.e. "actual") result with: 5.0.4, 5.0.3 and 4.4.x, so this problem wasn't introduced in 5.1.1.
Also I should note that changing StructAddNodePointer definition to "function &StructAddNodePointer()" fixes it.
Dmitry, please take a look at it.
 [2006-01-09 10:30 UTC] dmitry@php.net
Tony is right.
This is not a PHP bug, but a user level error.

The code should be:

function &StructAddNodePointer(...



 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 15 04:01:33 2025 UTC