<?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"
	>
<channel>
	<title>Comments on: The static keyword in PHP5</title>
	<atom:link href="http://lukebaker.org/archives/2007/02/11/the-static-keyword-in-php5/feed/" rel="self" type="application/rss+xml" />
	<link>http://lukebaker.org/archives/2007/02/11/the-static-keyword-in-php5/</link>
	<description>lukebaker.org</description>
	<pubDate>Tue, 06 Jan 2009 08:37:59 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Luke</title>
		<link>http://lukebaker.org/archives/2007/02/11/the-static-keyword-in-php5/#comment-1450</link>
		<dc:creator>Luke</dc:creator>
		<pubDate>Tue, 13 Feb 2007 19:16:30 +0000</pubDate>
		<guid isPermaLink="false">http://lukebaker.org/archives/2007/02/11/the-static-keyword-in-php5/#comment-1450</guid>
		<description>Joel,

I tried a ton of different things when messing with that.  In fact, it turns out that in PHP4 you can figure out the class name by going through the backtrace, though for some reason this was removed in PHP5.

The get_class() example I used wasn't a very good one, but it was the clearest way I could think of to show an example of the problem.  The __CLASS__ magic constant does behave differently, as it will always return the class name from which it is called.  If you replace my get_class() function calls with __CLASS__, you end up getting 'Foo' for both of those functions.

As you seem to be suggesting, if I used the __CLASS__ constant in the inherited classes, then it would return the correct inherited class name.  In the scenario I was working on, I didn't want to clutter every inherited class with this duplicated code.</description>
		<content:encoded><![CDATA[<p>Joel,</p>
<p>I tried a ton of different things when messing with that.  In fact, it turns out that in PHP4 you can figure out the class name by going through the backtrace, though for some reason this was removed in PHP5.</p>
<p>The get_class() example I used wasn&#8217;t a very good one, but it was the clearest way I could think of to show an example of the problem.  The __CLASS__ magic constant does behave differently, as it will always return the class name from which it is called.  If you replace my get_class() function calls with __CLASS__, you end up getting &#8216;Foo&#8217; for both of those functions.</p>
<p>As you seem to be suggesting, if I used the __CLASS__ constant in the inherited classes, then it would return the correct inherited class name.  In the scenario I was working on, I didn&#8217;t want to clutter every inherited class with this duplicated code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: joel boonstra</title>
		<link>http://lukebaker.org/archives/2007/02/11/the-static-keyword-in-php5/#comment-1448</link>
		<dc:creator>joel boonstra</dc:creator>
		<pubDate>Mon, 12 Feb 2007 19:30:18 +0000</pubDate>
		<guid isPermaLink="false">http://lukebaker.org/archives/2007/02/11/the-static-keyword-in-php5/#comment-1448</guid>
		<description>Luke,

Have you tried the '__CLASS__' magic constant inside the base and inherited classes? I don't know for sure if it would behave differently from using the get_class() function, but it might.

One place I like to use static data members is to store an instance of the class object to implement Singleton.  You'd have a private $_instance static member, and then a static public member function that instantiates $_instance if not already set, and then returns $_instance.  You could also declare the __construct() method to be private (or protected) to disallow direct class instantiation.

I like PHP5.</description>
		<content:encoded><![CDATA[<p>Luke,</p>
<p>Have you tried the &#8216;__CLASS__&#8217; magic constant inside the base and inherited classes? I don&#8217;t know for sure if it would behave differently from using the get_class() function, but it might.</p>
<p>One place I like to use static data members is to store an instance of the class object to implement Singleton.  You&#8217;d have a private $_instance static member, and then a static public member function that instantiates $_instance if not already set, and then returns $_instance.  You could also declare the __construct() method to be private (or protected) to disallow direct class instantiation.</p>
<p>I like PHP5.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.116 seconds -->
