Miscellaneous ⇒ User & Newbie Resources :: Archives ⇒ "=&" what is it? :: Archived ⇒ Community Forums ⇒ CPG Dragonfly™ CMS
Forum IndexUser & Newbie Resources

Archived ⇒ "=&" what is it?


what does the "=&" mean? I can't seem to find it in any documentation.

Search is your friend

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Fedora Core 1, Apache 1.3.33, Mysql 4.1.14, PHP 5.0.5 w/ APC cache, Dragonfly 9.0.6.1


tank wrote
what does the "=&" mean? I can't seem to find it in any documentation.


In PHP, according to "Programming PHP" by O'Reilly.

Bitwise-AND-equals (&=)
Performs a bitwise AND on the value of the lefthand operand and the righthand operand, then assigns the result to the lefthand operand.


Is this what you wanted?

- |\\/|ystic

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Ubuntu 14.04.1/Apache 2/5.5.38/5.5.9/9.4.0.0


=& is a refence syntax. Meaning that both $var, etc have the same value, and if you change the value of one the other changes also . ( "dude" translation ).

Ex.

$test = 'test';
$test2 =& $test;

$test = "I've changed";

echo "$test <br/> $test2"; This would show the same value for both

Readmore about it here
www.php.net/manual/en/...whatdo.php

Edit: Also read here
www.php.net/manual/en/...rences.php

What is The Viperal ?
Email: viperal1 @ gmail.com

Please enter your server specs in your user profile! 😢

Last edited by Viperal on Fri Sep 09, 2005 2:44 pm; edited 1 time in total


www.hudzilla.org/phpbo...php/3_12_3

if it were like C++ i would tell you that it's assigning the memory adress to whatever is at the left side. therefore becoming a pointer (since it's a loosly written language that's completely possible). if it has the adress and not the actual value it's actually faster because it holds just a few bytes of information instead of whatever it could have been. like a whole movie or a struct or class which all would be MUCH bigger than a pointer.

that's how i understand it. there was another variable that used that operator and i'm quite sure that's what's happening

i'm just that sweet

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Windows XP | P4HT 3.4| 1.5GB RAM | 256 Vid Card PCIX | Apache2.0.52 | MySQL 1.4.8 | PHP 4.3.10 | 9.03


very nice. thanks for the info

Search is your friend

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Fedora Core 1, Apache 1.3.33, Mysql 4.1.14, PHP 5.0.5 w/ APC cache, Dragonfly 9.0.6.1


ok. so it isn't like C++ then. forget me

i'm just that sweet

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Windows XP | P4HT 3.4| 1.5GB RAM | 256 Vid Card PCIX | Apache2.0.52 | MySQL 1.4.8 | PHP 4.3.10 | 9.03


Some more detail on the subject...

$text2 = 'huge string of 1Mb';

Now i do this:

$text2 = $text1;

This will copy the whole 1Mb in memory so actual the data will be in memory 2 times which makes it 2Mb.
Secondly copying data is a slow process and if you don't need manipulation of the data OR you need manipulation and return the manipulated data then it's easier to use references (aka pointers in C++) then to:

- copy $text1 to $text2
- modify $text2
- copy $text2 to $text1

instead you do:

- $text2 points to $text1
- modify $text2 (and $text1 at the same time)

This only uses 1Mb of memory and is a lot faster since it only needs to copy the pointer.
A pointer is a 32bit integer which, as it says, points to somewhere in the memory.

In c++ this kind of behavior is very familiar using the * instead of a & but it's also much more dangerous then in php and this has to do with code cleaning.
Since it points to somewhere in memory you can easily change that pointer but in the meen time that other data is still in memory but no-one knows where anymore cos the pointer value was changed. This is know as a memory leak.

$text1 = 'test1';
$text2 = 'test2'
$text3 =& $text1;
$text1 = null;
$text3 =& $text2;

now 'test1' is still floating somewhere in memory.

$text1 = 'test1';
$text2 = 'test2'
$text3 =& $text1;
$text1 = null;
unset($text3);
$text3 =& $text2;

Now we have properly cleared the memory.

In PHP this is not such a issue because PHP tracks where and what is put in memory (say it has a list of pointers to anything in memory untill you unset) in C++ however your app will be a huge memory leaker.

I hope this clarifies that referencing is nice but be carefull.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Fedora 25 / Apache 2.4.27 / MariaDB 10.1.26 / PHP 7.1.10 / Mercurial


that's why you always check your pointers in C++. i always have and rarely do i have a major memory leak. but it always gets cleaned up cuz i check for it. to make sure of course, otherwise that's just terrible programming.

but yea, that clears it up alot more. thanx

i'm just that sweet

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Windows XP | P4HT 3.4| 1.5GB RAM | 256 Vid Card PCIX | Apache2.0.52 | MySQL 1.4.8 | PHP 4.3.10 | 9.03

All times are UTC