<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>Comments on: Why Do Some PHP Variables Have an Ampersand Before Them?</title>
	<atom:link href="https://www.webmaster-source.com/2010/02/25/why-do-some-php-variables-have-an-ampersand-before-them/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.webmaster-source.com/2010/02/25/why-do-some-php-variables-have-an-ampersand-before-them/</link>
	<description>Useful Resources For Webmasters</description>
	<lastBuildDate>Mon, 04 May 2026 06:57:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.42</generator>
	<item>
		<title>By: Nikos</title>
		<link>https://www.webmaster-source.com/2010/02/25/why-do-some-php-variables-have-an-ampersand-before-them/#comment-19445</link>
		<dc:creator><![CDATA[Nikos]]></dc:creator>
		<pubDate>Tue, 24 May 2011 18:18:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.webmaster-source.com/?p=3054#comment-19445</guid>
		<description><![CDATA[Hi , 
This functionality is depreciated from PHP5.2 .
If you tray to run PEAR packages on PHP5.3 you get a lot of error messages that values by reference are depreciated .]]></description>
		<content:encoded><![CDATA[<p>Hi ,<br />
This functionality is depreciated from PHP5.2 .<br />
If you tray to run PEAR packages on PHP5.3 you get a lot of error messages that values by reference are depreciated .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Rodger</title>
		<link>https://www.webmaster-source.com/2010/02/25/why-do-some-php-variables-have-an-ampersand-before-them/#comment-11043</link>
		<dc:creator><![CDATA[David Rodger]]></dc:creator>
		<pubDate>Thu, 04 Mar 2010 10:48:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.webmaster-source.com/?p=3054#comment-11043</guid>
		<description><![CDATA[&gt;array(&amp;$this,&#039;admin_scripts&#039;)
[...snip...]
&gt;passing an array with a class and method combination,
&gt;instead of just a function name

Well, an object reference and a function name.

In this case (and not the examples which follow), it&#039;s because Matt Mullenweg insists on maintaining compatibility with PHP4, despite the fact that support for PHP4 &lt;a href=&quot;http://www.php.net/archive/2007.php#2007-07-13-1&quot; rel=&quot;nofollow&quot;&gt;ended years ago&lt;/a&gt;.]]></description>
		<content:encoded><![CDATA[<p>&gt;array(&amp;$this,&#8217;admin_scripts&#8217;)<br />
[&#8230;snip&#8230;]<br />
&gt;passing an array with a class and method combination,<br />
&gt;instead of just a function name</p>
<p>Well, an object reference and a function name.</p>
<p>In this case (and not the examples which follow), it&#8217;s because Matt Mullenweg insists on maintaining compatibility with PHP4, despite the fact that support for PHP4 <a href="http://www.php.net/archive/2007.php#2007-07-13-1" rel="nofollow">ended years ago</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michal Kozak</title>
		<link>https://www.webmaster-source.com/2010/02/25/why-do-some-php-variables-have-an-ampersand-before-them/#comment-10985</link>
		<dc:creator><![CDATA[Michal Kozak]]></dc:creator>
		<pubDate>Thu, 25 Feb 2010 14:34:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.webmaster-source.com/?p=3054#comment-10985</guid>
		<description><![CDATA[SORRY, I made a mistake there. This is correct:

$myArr = array (0 =&gt; “before change”);
foreach($myArr as &amp;$element) {
$element = “after change”;
}
print_r($myArr);]]></description>
		<content:encoded><![CDATA[<p>SORRY, I made a mistake there. This is correct:</p>
<p>$myArr = array (0 =&gt; “before change”);<br />
foreach($myArr as &amp;$element) {<br />
$element = “after change”;<br />
}<br />
print_r($myArr);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michal Kozak</title>
		<link>https://www.webmaster-source.com/2010/02/25/why-do-some-php-variables-have-an-ampersand-before-them/#comment-10984</link>
		<dc:creator><![CDATA[Michal Kozak]]></dc:creator>
		<pubDate>Thu, 25 Feb 2010 14:10:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.webmaster-source.com/?p=3054#comment-10984</guid>
		<description><![CDATA[Of course there is a performance benefit of doing so :). Not only that, it’s also less coding.

First of all when you do something like:

$b = &amp;$a;

You avoid arduous copying process which speeds up the whole program.

Another example is when you’re using “foreach” loop for working with arrays. If you apply some changes inside foreach loop to array’s values, the original array will not be modified, since what you have inside foreach loop is just the copy – so you’ll modify just the copy, not the original.

When you use &amp; before particular array’s value to refference to the original – thus any change to the copy will also affect the original:

$myArr = array (0 =&gt; “before change”);
foreach($myArr as $id =&gt; &amp;$element) {
$element[$id] = “after change”;
}
print_r($myArr);

When you print $myArr you’ll see “after change”. If you would you &amp; before $element in the loop, like this:

foreach($myArr as $element)

You’d see the “before change” when you’d print the $myArr.
Hope I epxlained it well  :)]]></description>
		<content:encoded><![CDATA[<p>Of course there is a performance benefit of doing so :). Not only that, it’s also less coding.</p>
<p>First of all when you do something like:</p>
<p>$b = &amp;$a;</p>
<p>You avoid arduous copying process which speeds up the whole program.</p>
<p>Another example is when you’re using “foreach” loop for working with arrays. If you apply some changes inside foreach loop to array’s values, the original array will not be modified, since what you have inside foreach loop is just the copy – so you’ll modify just the copy, not the original.</p>
<p>When you use &amp; before particular array’s value to refference to the original – thus any change to the copy will also affect the original:</p>
<p>$myArr = array (0 =&gt; “before change”);<br />
foreach($myArr as $id =&gt; &amp;$element) {<br />
$element[$id] = “after change”;<br />
}<br />
print_r($myArr);</p>
<p>When you print $myArr you’ll see “after change”. If you would you &amp; before $element in the loop, like this:</p>
<p>foreach($myArr as $element)</p>
<p>You’d see the “before change” when you’d print the $myArr.<br />
Hope I epxlained it well  <img src="https://www.webmaster-source.com/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Martin</title>
		<link>https://www.webmaster-source.com/2010/02/25/why-do-some-php-variables-have-an-ampersand-before-them/#comment-10982</link>
		<dc:creator><![CDATA[Michael Martin]]></dc:creator>
		<pubDate>Thu, 25 Feb 2010 13:01:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.webmaster-source.com/?p=3054#comment-10982</guid>
		<description><![CDATA[Ah, that&#039;s pretty cool Matt. Would be interesting to see if there really was a performance benefit and what it would be, like you suggested! :)]]></description>
		<content:encoded><![CDATA[<p>Ah, that&#8217;s pretty cool Matt. Would be interesting to see if there really was a performance benefit and what it would be, like you suggested! <img src="https://www.webmaster-source.com/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /></p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/


Served from: www.webmaster-source.com @ 2026-05-04 03:37:35 by W3 Total Cache
-->