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

Reference to reference?

P: n/a
Today I discovered that I don't understand how references work in php.
I create object, then I store reference to this object into array.
Then I do so into another array. And suddenly I have two vars taken by
reference which should point to single object, but they are different.

Is there possibility of "reference to reference" in php?
I'm just going crazy, can't figure out everything...

Feb 1 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
By saying "reference to reference" I mean something like &&$var
So that &$var !== &&$var

Feb 1 '07 #2

P: n/a
Yes, you should have no trouble in doing someting like:

<?
$x = 1000;
$y = &$x;
$z = &$y;
?>

In final $y will be like $z.

I think that is what you are asking for.

Jose Silva
http://www.t6m.com

On Feb 1, 1:49 pm, "Tamagafk" <tamag...@gmail.comwrote:
Today I discovered that I don't understand how references work in php.
I create object, then I store reference to this object into array.
Then I do so into another array. And suddenly I have two vars taken by
reference which should point to single object, but they are different.

Is there possibility of "reference to reference" in php?
I'm just going crazy, can't figure out everything...

Feb 1 '07 #3

P: n/a
On Thu, 01 Feb 2007 05:49:31 -0800, Tamagafk <ta******@gmail.comwrote:
Today I discovered that I don't understand how references work in php.
I create object, then I store reference to this object into array.
Then I do so into another array. And suddenly I have two vars taken by
reference which should point to single object, but they are different.

Is there possibility of "reference to reference" in php?
I'm just going crazy, can't figure out everything...
Why don't you post your code? Unfortunately, we didn't see you coding
first hand, so we can't pinpoint what's wrong. This is an example of what
works:

<?php
$o = new a('hello, world');
$o2 = new a('goodbye, cruel world');

$array['foo'] =& $o;
$array['foo2'] =& $o2;

echo $array['foo']->getFoo(); // outputs 'hello, world'
$o->setFoo('como estas');
echo $array['foo']->getFoo(); // outputs 'como estas'

$array['foo2']->setFoo("kon'nichi wa");
echo $o2->getFoo(); // outputs "kon'nichi wa"
?>

--
Curtis, http://dyersweb.com
Feb 3 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.