By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,053 Members | 1,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,053 IT Pros & Developers. It's quick & easy.

Pointer in PHP

P: n/a
Hi,

Is it possible to keep a pointer to an object in a PHP variable? I'd like to
do this :

$obj1 = new myClass(...);
$obj2 = $obj1;
$obj1->name = "foo";
$obj2->name = "bar";

echo $obj1->name;

Which would display "bar" instead of "foo" with the current PHP behavior.

Thanks a lot,
Denis


Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Denis Crespe" <a@a.com> wrote in message
news:bn**********@news.tiscali.fr...
$obj1 = new myClass(...);
$obj2 = $obj1;
$obj1->name = "foo";
$obj2->name = "bar";

echo $obj1->name;

Which would display "bar" instead of "foo" with the current PHP behavior.


you can not get the pointer, but you can get the reference:

$obj2 = & $obj1;

rush
--
http://www.templatetamer.com/

Jul 17 '05 #2

P: n/a
Awesome! It's what I wanted :-)

Denis

"rush" <pi**@rush.avalon.hr> a écrit dans le message de news:
bn**********@ls219.htnet.hr...
"Denis Crespe" <a@a.com> wrote in message
news:bn**********@news.tiscali.fr...
$obj1 = new myClass(...);
$obj2 = $obj1;
$obj1->name = "foo";
$obj2->name = "bar";

echo $obj1->name;

Which would display "bar" instead of "foo" with the current PHP
behavior.
you can not get the pointer, but you can get the reference:

$obj2 = & $obj1;

rush
--
http://www.templatetamer.com/

Jul 17 '05 #3

P: n/a
Denis Crespe wrote:
Hi,

Is it possible to keep a pointer to an object in a PHP variable? I'd like to
do this :

$obj1 = new myClass(...);
$obj2 = $obj1;
$obj1->name = "foo";
$obj2->name = "bar";

echo $obj1->name;

Which would display "bar" instead of "foo" with the current PHP behavior.

Thanks a lot,
Denis

$obj2 = &$obj1;

--
John Downey
http://delusive.dyn.ee
http://sage.dev.box.sk
http://blacksun.box.sk

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.