=&<

liunx

Guest
I was looking at some example php code and saw the following instantiation of a class:

$lclVariableName =& new ClassName;

I know the & can serve as a reference operator, but I haven't seen it used in this way, i.e. =&

Could someone explain exactly what this =& means?

Thanks!That puzzles me too, when used like that. I can't really imagine that it has any function at all. Maybe it's just a mistake in the code, but it doesn't throw any error? Not sure though, maybe it has a purpose.
=& isn't an operator though... Don't let it confuse you, that the = and the & are written together.


$answer = 'No';
$reply = &$answer; // doesn't matter if it's =&$var or = &$var.
$answer = 'Yes';
echo $reply; // echoes 'Yes'.Yeah, it doesn't seem to make any visible difference whether or not I have the '&' in the code. It doesn't throw an error when the '&' is there. I ran the example code (where the =& was used in the instantiation of a class object). It acted the same(it seemed to work) whether I had the '=&' or just '='it is an Operator, but I seem to have forgotten what it is for. I think it has somethign to do with association. when I find my notes I will post again.

it is perfectly valid too.Hmm I browsed through <!-- m --><a class="postlink" href="http://www.php.net/language.operators">http://www.php.net/language.operators</a><!-- m --> but I didn't find it.. How can that be a special operator? The engine wouldn't be able to tell =& $something and =&$something(i.e. = &$something) apart, which would then mean two different things.. &= is an operator though, but I've never used it.. I think it's used in the other direction, somehow.I think:

//makes a NEW instance of the class

$test = new ClassName();

//makes a COPY of the current class

$test =& new ClassName();Originally posted by willamoose
I think:

//makes a NEW instance of the class

$test = new ClassName();

//makes a COPY of the current class

$test =& new ClassName();


Copy of the current class? What's the current class? When I want to make a copy of a class, I use CTRL+C and CTRL+V. Why would you make a copy of a class in the code? Objects are copied, not classes. $newObject = $oldObject would achieve that. Right? Or else there's something to PHP that I've really overseen..Originally posted by Rydberg
Copy of the current class? What's the current class? When I want to make a copy of a class, I use CTRL+C and CTRL+V. Why would you make a copy of a class in the code? Objects are copied, not classes. $newObject = $oldObject would achieve that. Right? Or else there's something to PHP that I've really overseen..

erk..I didn't say I was right..it's just what I thought it was from hearing about it...what I meant was copy the current (pardon) object's properties(variable settings,etc.)Hmm read my post again and it came out a bit harsh, sorry wasn't meant that way :)
But what do you mean with the current object's properties? There is no object yet, new ClassName() creates a new object, making $test the first known object...
 
Back
Top