ridiculous Posted July 27, 2008 Share Posted July 27, 2008 I'm trying to learn OO PHP and I'm seeing a lot of code snippets on PHP.net that include .= and =& . I've searched these terms on GOOGLE and YAHOO! with little success. Can anyone fill me in? Thanks. Link to comment https://forums.phpfreaks.com/topic/116807-solved-what-is-the-purpose-of-using-and-amp/ Share on other sites More sharing options...
JasonLewis Posted July 27, 2008 Share Posted July 27, 2008 You can use them to join two strings together. I don't use =& but I'm positive it does the same thing. Example: $str = "Hello this is a string"; $str .= " that will be joined!"; echo $str; Link to comment https://forums.phpfreaks.com/topic/116807-solved-what-is-the-purpose-of-using-and-amp/#findComment-600677 Share on other sites More sharing options...
ridiculous Posted July 27, 2008 Author Share Posted July 27, 2008 Awesome. So its essentially a shorter way of going: $str = "This is"; $str = $str."some text"; Link to comment https://forums.phpfreaks.com/topic/116807-solved-what-is-the-purpose-of-using-and-amp/#findComment-600678 Share on other sites More sharing options...
JasonLewis Posted July 27, 2008 Share Posted July 27, 2008 Sure is. Link to comment https://forums.phpfreaks.com/topic/116807-solved-what-is-the-purpose-of-using-and-amp/#findComment-600679 Share on other sites More sharing options...
ridiculous Posted July 27, 2008 Author Share Posted July 27, 2008 Thanks a lot for the help! Link to comment https://forums.phpfreaks.com/topic/116807-solved-what-is-the-purpose-of-using-and-amp/#findComment-600680 Share on other sites More sharing options...
DarkWater Posted July 27, 2008 Share Posted July 27, 2008 Precisely. Just like +=, -=, *=, and /=. Where did you see =&? That's not a shorthand operator. Did you see something like: $var = & new someClass(); >_> Link to comment https://forums.phpfreaks.com/topic/116807-solved-what-is-the-purpose-of-using-and-amp/#findComment-600681 Share on other sites More sharing options...
ridiculous Posted July 27, 2008 Author Share Posted July 27, 2008 Example #6 Object Assignment <?php $assigned = $instance; $reference =& $instance; $instance->var = '$assigned will have this value'; $instance = null; // $instance and $reference become null var_dump($instance); var_dump($reference); var_dump($assigned); ?> http://www.php.net/manual/en/language.oop5.basic.php Link to comment https://forums.phpfreaks.com/topic/116807-solved-what-is-the-purpose-of-using-and-amp/#findComment-600684 Share on other sites More sharing options...
DarkWater Posted July 27, 2008 Share Posted July 27, 2008 Yeah, it's the reference operator. It's not a shorthand thing. You use it to make a variable a reference to another object so changes to either affect both variables sort of. Almost like C++ pointers, but not quite. =P Link to comment https://forums.phpfreaks.com/topic/116807-solved-what-is-the-purpose-of-using-and-amp/#findComment-600685 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.