php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #4415 Nested obj ref in array doesn't see scalar changes
Submitted: 2000-05-11 22:22 UTC Modified: 2000-05-31 09:46 UTC
From: holloway at io dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0 Release Candidate 2 OS: Linux RedHat 6.0
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: holloway at io dot com
New email:
PHP Version: OS:

 

 [2000-05-11 22:22 UTC] holloway at io dot com
<?

class B {

	var $_x;

	function B($val) {
		$this->_x = $val;
	}
	
	function getVal() {
		return $this->_x;
	}

	function setVal ($v) {
		$this->_x = $v;
	}
}


class A {

	var $_bObjArr;
	var $_b;

	function A ($value) {
		// Creates a new B object.
		$this->_b = new B($value);

		// Should copy its reference pointer to element
		// 1 of an array.
		$this->_bObjArr[1] = $this->_b;
	}

	function setBValInArr($value) {
		$tmp_bobj = $this->_bObjArr[1];
		$tmp_bobj->setVal($value);
	}

	function setScalarBVal($value) {
		$this->_b->setVal($value);
	}
		
	function getScalarVal () {
		return $this->_b->getVal();
	}

	function getArrVal () {
		$tmp_b = $this->_bObjArr[1];
		return $tmp_b->getVal();
	}
}
// Inside A object constructor, instantiates a B object, sets value of its
// $_x variable to 4, creates a copy of its reference pointer into an
// array.
$a = new A(4);
print "B obj. instantiated with x value 4.<br><br>";

print "Scalar retrieved value = " . $a->getScalarVal() . "<br>";
print "Array pointer retrieved value = " . $a->getArrVal() . "<br><br>";

$a->setScalarBVal(99);
print "\$_x set to <b>99</b> by SCALAR, retrieved by SCALAR.  ";
print "Retrieved value = <b>" . $a->getScalarVal() . "</b><br><br>";

$a->setScalarBVal(99);
print "\$_x set to <b>99</b> by SCALAR, retrieved by ARRAY PTR.  ";
print "Retrieved value = <b>" . $a->getArrVal() . "</b><br><br>";

$a->setBValInArr(99);
print "\$_x set to <b>99</b> by ARRAY PTR, retrieved by SCALAR.  ";
print "Retrieved value = <b>" . $a->getScalarVal() . "</b><br><br>";

$a->setBValInArr(99);
print "\$_x set to <b>99</b> by ARRAY PTR, retrieved by ARRAY PTR.  ";
print "Retrieved value = <b>" . $a->getArrVal() . "</b><br><br>";
?>

I configured PHP 4.0RC2 as static with configure line
./configure --with-mysql --with-apache=../apache_1.3.x --enable-track-vars --enable-track-sid

I don't think my php.ini is relevant.  I'll be glad to provide it.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-05-31 09:46 UTC] stas at cvs dot php dot net
Seems that you use PHP as you would use Java. PHP assignments work by by value
unless you explicitly make them work by reference like: $a = &$b
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 09 23:01:33 2025 UTC