<?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 for Bashar's Blog</title>
	<atom:link href="http://bashar.alfallouji.com/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://bashar.alfallouji.com</link>
	<description>Talks around PHP, Computer Science and Stuffs</description>
	<pubDate>Thu, 11 Mar 2010 19:51:47 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>Comment on PHP Autoload Manager by Apprendre a utiliser Git&#160;&#124;&#160;Anis Berejeb</title>
		<link>http://bashar.alfallouji.com/php-autoload-manager/comment-page-1/#comment-3056</link>
		<dc:creator>Apprendre a utiliser Git&#160;&#124;&#160;Anis Berejeb</dc:creator>
		<pubDate>Sun, 01 Nov 2009 00:10:24 +0000</pubDate>
		<guid isPermaLink="false">http://bashar.alfallouji.com/?page_id=160#comment-3056</guid>
		<description>[...] chez github. essayons de &#171;&#160;checkouter&#187;&#160; un projet. Je choisis le projet PHP AUTOLOAD MANAGER de Bashar : ?View Code SHELL1 2 3 4 5 6 7 8 9 ~$ git clone [...]</description>
		<content:encoded><![CDATA[<p>[...] chez github. essayons de &laquo;&nbsp;checkouter&raquo;&nbsp; un projet. Je choisis le projet PHP AUTOLOAD MANAGER de Bashar : ?View Code SHELL1 2 3 4 5 6 7 8 9 ~$ git clone [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on About me by Sheila</title>
		<link>http://bashar.alfallouji.com/about-me/comment-page-1/#comment-2057</link>
		<dc:creator>Sheila</dc:creator>
		<pubDate>Thu, 23 Jul 2009 20:30:30 +0000</pubDate>
		<guid isPermaLink="false">http://bashar.alfallouji.com/?page_id=327#comment-2057</guid>
		<description>BAF rocks!</description>
		<content:encoded><![CDATA[<p>BAF rocks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on PHP can be tricky sometimes &#8230; by anis berejeb</title>
		<link>http://bashar.alfallouji.com/2009/05/17/php-can-be-tricky-sometimes/comment-page-1/#comment-1051</link>
		<dc:creator>anis berejeb</dc:creator>
		<pubDate>Sun, 14 Jun 2009 18:16:12 +0000</pubDate>
		<guid isPermaLink="false">http://bashar.alfallouji.com/?p=269#comment-1051</guid>
		<description>I think that there is no ambiguity because what is passed in the :
$res = changeObj($obj = new StdClass()); 
is actually the result of the expression $obj = new stdClass(); and not $obj itself.</description>
		<content:encoded><![CDATA[<p>I think that there is no ambiguity because what is passed in the :<br />
$res = changeObj($obj = new StdClass());<br />
is actually the result of the expression $obj = new stdClass(); and not $obj itself.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on PHP can be tricky sometimes &#8230; by Pascal G.</title>
		<link>http://bashar.alfallouji.com/2009/05/17/php-can-be-tricky-sometimes/comment-page-1/#comment-965</link>
		<dc:creator>Pascal G.</dc:creator>
		<pubDate>Wed, 10 Jun 2009 14:20:03 +0000</pubDate>
		<guid isPermaLink="false">http://bashar.alfallouji.com/?p=269#comment-965</guid>
		<description>In C#, as soon as you define a parameter as an output parameter, the compiler will force you to pass a variable as parameter.  It won't allow expression as parameter.

Won't compile:
stdClass res = changeObj(ref new stdClass());

stdClass obj;
stdClass res = changeObj(ref obj = new stdClass());

Will compile:
stdClass obj = new stdClass(0;
stdClass res = changeObj(ref obj);

So the only one that compiles has no ambiguous behavior.</description>
		<content:encoded><![CDATA[<p>In C#, as soon as you define a parameter as an output parameter, the compiler will force you to pass a variable as parameter.  It won&#8217;t allow expression as parameter.</p>
<p>Won&#8217;t compile:<br />
stdClass res = changeObj(ref new stdClass());</p>
<p>stdClass obj;<br />
stdClass res = changeObj(ref obj = new stdClass());</p>
<p>Will compile:<br />
stdClass obj = new stdClass(0;<br />
stdClass res = changeObj(ref obj);</p>
<p>So the only one that compiles has no ambiguous behavior.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on PHP can be tricky sometimes &#8230; by Bashar</title>
		<link>http://bashar.alfallouji.com/2009/05/17/php-can-be-tricky-sometimes/comment-page-1/#comment-929</link>
		<dc:creator>Bashar</dc:creator>
		<pubDate>Thu, 04 Jun 2009 15:10:18 +0000</pubDate>
		<guid isPermaLink="false">http://bashar.alfallouji.com/?p=269#comment-929</guid>
		<description>Indeed, since PHP5, objects are always passed by reference. 


Pascal, isn't the behavior you are describing true in C# ?</description>
		<content:encoded><![CDATA[<p>Indeed, since PHP5, objects are always passed by reference. </p>
<p>Pascal, isn&#8217;t the behavior you are describing true in C# ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on PHP can be tricky sometimes &#8230; by Robert van der Linde</title>
		<link>http://bashar.alfallouji.com/2009/05/17/php-can-be-tricky-sometimes/comment-page-1/#comment-928</link>
		<dc:creator>Robert van der Linde</dc:creator>
		<pubDate>Wed, 03 Jun 2009 16:04:12 +0000</pubDate>
		<guid isPermaLink="false">http://bashar.alfallouji.com/?p=269#comment-928</guid>
		<description>This is basic PHP behavior and should be well known if you've been using PHP for a while. Objects are always passed by reference which makes sense. Literals are not</description>
		<content:encoded><![CDATA[<p>This is basic PHP behavior and should be well known if you&#8217;ve been using PHP for a while. Objects are always passed by reference which makes sense. Literals are not</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on PHP Autoload Manager by bashar</title>
		<link>http://bashar.alfallouji.com/php-autoload-manager/comment-page-1/#comment-834</link>
		<dc:creator>bashar</dc:creator>
		<pubDate>Sun, 31 May 2009 11:47:41 +0000</pubDate>
		<guid isPermaLink="false">http://bashar.alfallouji.com/?page_id=160#comment-834</guid>
		<description>Anis, Thanks for the comment. Glad to hear you like it.</description>
		<content:encoded><![CDATA[<p>Anis, Thanks for the comment. Glad to hear you like it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on PHP Autoload Manager by anis berejeb</title>
		<link>http://bashar.alfallouji.com/php-autoload-manager/comment-page-1/#comment-809</link>
		<dc:creator>anis berejeb</dc:creator>
		<pubDate>Sat, 30 May 2009 17:11:06 +0000</pubDate>
		<guid isPermaLink="false">http://bashar.alfallouji.com/?page_id=160#comment-809</guid>
		<description>very cool ! this will help me a lot :P</description>
		<content:encoded><![CDATA[<p>very cool ! this will help me a lot <img src='http://bashar.alfallouji.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on PHP Code Comparator by Bashar&#8217;s Blog &#187; PHP Code Comparator - Detect Code Changes</title>
		<link>http://bashar.alfallouji.com/php-code-comparator/comment-page-1/#comment-768</link>
		<dc:creator>Bashar&#8217;s Blog &#187; PHP Code Comparator - Detect Code Changes</dc:creator>
		<pubDate>Fri, 29 May 2009 07:36:39 +0000</pubDate>
		<guid isPermaLink="false">http://bashar.alfallouji.com/?page_id=323#comment-768</guid>
		<description>[...] PHP Code Comparator [...]</description>
		<content:encoded><![CDATA[<p>[...] PHP Code Comparator [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on PHP can be tricky sometimes &#8230; by Pascal G.</title>
		<link>http://bashar.alfallouji.com/2009/05/17/php-can-be-tricky-sometimes/comment-page-1/#comment-567</link>
		<dc:creator>Pascal G.</dc:creator>
		<pubDate>Fri, 22 May 2009 16:46:00 +0000</pubDate>
		<guid isPermaLink="false">http://bashar.alfallouji.com/?p=269#comment-567</guid>
		<description>Looks like the behavior is as soon as an expression is passed as parameter, the reference is lost.  I guess that what is happening is an implicit memory allocation is done to store the result of the expression and this is passed by reference instead of the variable.  We cannot "see" this memory allocation because we do not have a variable defined for it.  Its lifetime is then just the for function call.

For the object example, even if you do not pass the object by reference it will work because an object variable is more like a pointer.  Passing an object by reference implies that you may want to change the "pointer" value (pointer of pointer).  So to rewrite your last example this way would lead to the same behavior as other examples:

function changeObj(&amp;$obj)
{
	$obj = new StdClass();
    $obj-&gt;id = 10;
    return $obj;
}

$res = changeObj($obj = new StdClass());

var_dump($obj-&gt;id);
var_dump($res-&gt;id);

OUTPUT:
null
10</description>
		<content:encoded><![CDATA[<p>Looks like the behavior is as soon as an expression is passed as parameter, the reference is lost.  I guess that what is happening is an implicit memory allocation is done to store the result of the expression and this is passed by reference instead of the variable.  We cannot &#8220;see&#8221; this memory allocation because we do not have a variable defined for it.  Its lifetime is then just the for function call.</p>
<p>For the object example, even if you do not pass the object by reference it will work because an object variable is more like a pointer.  Passing an object by reference implies that you may want to change the &#8220;pointer&#8221; value (pointer of pointer).  So to rewrite your last example this way would lead to the same behavior as other examples:</p>
<p>function changeObj(&amp;$obj)<br />
{<br />
	$obj = new StdClass();<br />
    $obj-&gt;id = 10;<br />
    return $obj;<br />
}</p>
<p>$res = changeObj($obj = new StdClass());</p>
<p>var_dump($obj-&gt;id);<br />
var_dump($res-&gt;id);</p>
<p>OUTPUT:<br />
null<br />
10</p>
]]></content:encoded>
	</item>
</channel>
</rss>
