Reply to Global references to objects

Your name:

Reply:


Posted by Lόpher Cypher on 12/29/05 16:07

Hi,

Suppose I instantiate an object $a and store it in a global array. Now,
if I change a property of $a, the property in $a will have the new
value, but the property in the global array will have the old one. Does
anyone know workarounds?

global $global;
$global = array();

class A {
var $i;

function A() {
$this->i = 0;
}

function chg() {
$this->i += 2;
}
}


$a = new A();
$global[0] = $a;
$b = new A();
$global[1] = $b;

// here $global[0]->i == $global[1]->i == $a->i == $b->i == 0

$a->chg();

// here $global[0]->i == 0, $a->i == 2

Is there a way to store an object by reference so that whenever its
properties change, the global array item would still be referring the
actual object and not a copy of it I assume it made on the assigment?

Thanks,
luph

[Back to original message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация