<?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: Digging deeper into PHP&#8217;s static scoping</title>
	<atom:link href="http://joshduck.com/blog/2010/03/19/exploring-phps-static-scoping/feed/" rel="self" type="application/rss+xml" />
	<link>http://joshduck.com/blog/2010/03/19/exploring-phps-static-scoping/</link>
	<description>It's a blog about the web, by Josh. Geddit?</description>
	<lastBuildDate>Mon, 31 Jan 2011 18:23:57 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: David Stockton</title>
		<link>http://joshduck.com/blog/2010/03/19/exploring-phps-static-scoping/comment-page-1/#comment-10082</link>
		<dc:creator>David Stockton</dc:creator>
		<pubDate>Fri, 30 Jul 2010 22:08:28 +0000</pubDate>
		<guid isPermaLink="false">http://joshduck.com/blog/?p=107#comment-10082</guid>
		<description>Josh,

Thanks for the post.  I ran into something similar the other day where the behavior was completely surprising.

I am familiar with how a static variable behaves inside a class vs its child classes.  What I ran into that was surprising was declaring a static variable inside a method (not a static method) in a class.  It seems that different instances of objects of that class will share the same static variable defined in the class between all instances.

Once you extend the class, the instances of the extended class will get their own variable.

[code]
class House
{
    public function openDoor()
    {
        static $openCount = 0;
        $openCount++;

        return $openCount;
    }

}

class Apartment extends House {}
[/code]

If you instantiate several House objects, the openDoor method will keep track of the number of times openDoor has been called across all instances of all House objects.  However, if you instantiate an Apartment object or several, those will then keep track of how many times openDoor has been called on the Apartment objects.

It&#039;s as though the static $openDoor variable is treated as a class level static except that it is only accessible within the method.

Thanks,
David</description>
		<content:encoded><![CDATA[<p>Josh,</p>
<p>Thanks for the post.  I ran into something similar the other day where the behavior was completely surprising.</p>
<p>I am familiar with how a static variable behaves inside a class vs its child classes.  What I ran into that was surprising was declaring a static variable inside a method (not a static method) in a class.  It seems that different instances of objects of that class will share the same static variable defined in the class between all instances.</p>
<p>Once you extend the class, the instances of the extended class will get their own variable.</p>
<p>[code]<br />
class House<br />
{<br />
    public function openDoor()<br />
    {<br />
        static $openCount = 0;<br />
        $openCount++;</p>
<p>        return $openCount;<br />
    }</p>
<p>}</p>
<p>class Apartment extends House {}<br />
[/code]</p>
<p>If you instantiate several House objects, the openDoor method will keep track of the number of times openDoor has been called across all instances of all House objects.  However, if you instantiate an Apartment object or several, those will then keep track of how many times openDoor has been called on the Apartment objects.</p>
<p>It&#8217;s as though the static $openDoor variable is treated as a class level static except that it is only accessible within the method.</p>
<p>Thanks,<br />
David</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: uberVU - social comments</title>
		<link>http://joshduck.com/blog/2010/03/19/exploring-phps-static-scoping/comment-page-1/#comment-7045</link>
		<dc:creator>uberVU - social comments</dc:creator>
		<pubDate>Sun, 04 Apr 2010 14:54:56 +0000</pubDate>
		<guid isPermaLink="false">http://joshduck.com/blog/?p=107#comment-7045</guid>
		<description>&lt;strong&gt;Social comments and analytics for this post...&lt;/strong&gt;

This post was mentioned on Twitter by joshduck: Exploring PHP&#039;s static scoping: http://joshduck.com/blog/2010/03/19/exploring-phps-static-scoping/ #php...</description>
		<content:encoded><![CDATA[<p><strong>Social comments and analytics for this post&#8230;</strong></p>
<p>This post was mentioned on Twitter by joshduck: Exploring PHP&#8217;s static scoping: <a href="http://joshduck.com/blog/2010/03/19/exploring-phps-static-scoping/" rel="nofollow">http://joshduck.com/blog/2010/03/19/exploring-phps-static-scoping/</a> #php&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Appuntamenti elettorali SEL Benevento &#124; Sinistra Ecologia Libertà - la Sinistra in provincia di Benevento</title>
		<link>http://joshduck.com/blog/2010/03/19/exploring-phps-static-scoping/comment-page-1/#comment-6760</link>
		<dc:creator>Appuntamenti elettorali SEL Benevento &#124; Sinistra Ecologia Libertà - la Sinistra in provincia di Benevento</dc:creator>
		<pubDate>Sat, 20 Mar 2010 17:32:09 +0000</pubDate>
		<guid isPermaLink="false">http://joshduck.com/blog/?p=107#comment-6760</guid>
		<description>[...] Josh on the Web » Blog Archive » Exploring PHP&#8217;s static scoping [...]</description>
		<content:encoded><![CDATA[<p>[...] Josh on the Web » Blog Archive » Exploring PHP&#8217;s static scoping [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Appuntamenti elettorali SEL Benevento &#124; Sinistra Ecologia Libertà - la Sinistra in provincia di Benevento</title>
		<link>http://joshduck.com/blog/2010/03/19/exploring-phps-static-scoping/comment-page-1/#comment-6729</link>
		<dc:creator>Appuntamenti elettorali SEL Benevento &#124; Sinistra Ecologia Libertà - la Sinistra in provincia di Benevento</dc:creator>
		<pubDate>Fri, 19 Mar 2010 11:29:00 +0000</pubDate>
		<guid isPermaLink="false">http://joshduck.com/blog/?p=107#comment-6729</guid>
		<description>[...] Josh on the Web » Blog Archive » Exploring PHP&#039;s static scoping [...]</description>
		<content:encoded><![CDATA[<p>[...] Josh on the Web » Blog Archive » Exploring PHP&#39;s static scoping [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

