<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>Crisis Averted!: PHP 5, static and inheritance</title>
    <link>http://socket7.net</link>
    <description>Crisis Averted!  A weblog by Brett Stimmerman.</description>
    <managingEditor>brettstimmerman@gmail.com (Brett Stimmerman)</managingEditor>
    <webMaster>brettstimmerman@gmail.com (Brett Stimmerman)</webMaster>
    <docs>http://backend.userland.com/rss</docs>
    <ttl>60</ttl>

  <item>
  <title>No title</title>
  <link>http://socket7.net/article/php-5-static-and-inheritance#comment-69</link>
  <author>Matthew Grdinic (http://www.sledxchange.com)</author>
  <description>
    ^ oops&lt;br /&gt;
&lt;br /&gt;
http://blog.felho.hu/what-is-new-in-php-53-part-2-late-static-binding.html  </description>
  <guid isPermaLink="true">http://socket7.net/article/php-5-static-and-inheritance#comment-69</guid>
  <pubDate>Tue, 18 Dec 2007 16:57:33 -0800</pubDate>
</item>
  <item>
  <title>Web Developer</title>
  <link>http://socket7.net/article/php-5-static-and-inheritance#comment-68</link>
  <author>Matthew Grdinic (http://www.sledxchange.com)</author>
  <description>
    php 5.3&lt;br /&gt;
&lt;a&gt;Late Static Binding&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Supposed to be out early 2008.  </description>
  <guid isPermaLink="true">http://socket7.net/article/php-5-static-and-inheritance#comment-68</guid>
  <pubDate>Tue, 18 Dec 2007 16:55:12 -0800</pubDate>
</item>
  <item>
  <title>Re: No title</title>
  <link>http://socket7.net/article/php-5-static-and-inheritance#comment-67</link>
  <author>Brett (http://socket7.net)</author>
  <description>
    Thanks for pointing this out Ben.  There is hope!  </description>
  <guid isPermaLink="true">http://socket7.net/article/php-5-static-and-inheritance#comment-67</guid>
  <pubDate>Mon, 03 Dec 2007 13:12:18 -0800</pubDate>
</item>
  <item>
  <title>No title</title>
  <link>http://socket7.net/article/php-5-static-and-inheritance#comment-66</link>
  <author>Ben (http://www.benlog.org)</author>
  <description>
    &lt;a href=&quot;http://bugs.php.net/bug.php?id=42681&quot;&gt;PHP bug #42681&lt;/a&gt; - status is 'assigned'.  </description>
  <guid isPermaLink="true">http://socket7.net/article/php-5-static-and-inheritance#comment-66</guid>
  <pubDate>Sat, 01 Dec 2007 19:43:59 -0800</pubDate>
</item>
  <item>
  <title>If the class is instantiated</title>
  <link>http://socket7.net/article/php-5-static-and-inheritance#comment-65</link>
  <author>James</author>
  <description>
    blah&lt;br /&gt;
&lt;br /&gt;
propertyDefinitions = self::$propertyDefinitions;&lt;br /&gt;
&lt;br /&gt;
// propertyDefinitions);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
However I doubt this is the best solution. There should be the ability to do&lt;br /&gt;
$className::whatever without eval or something :/  </description>
  <guid isPermaLink="true">http://socket7.net/article/php-5-static-and-inheritance#comment-65</guid>
  <pubDate>Wed, 28 Nov 2007 00:43:48 -0800</pubDate>
</item>
  <item>
  <title>Alternative to Tom's method</title>
  <link>http://socket7.net/article/php-5-static-and-inheritance#comment-55</link>
  <author>toby (http://bezoe.com)</author>
  <description>
    I've used this method for getting a calling subclass's class constants.  The problem is that the interpretor will not catch syntax errors in the eval until the statement is executed.&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
$className = get_class($this);&lt;br /&gt;
return eval(&quot;return $className::table;&quot;);&lt;br /&gt;
&lt;/code&gt;  </description>
  <guid isPermaLink="true">http://socket7.net/article/php-5-static-and-inheritance#comment-55</guid>
  <pubDate>Mon, 22 Oct 2007 01:03:37 -0700</pubDate>
</item>
  <item>
  <title>Possibility</title>
  <link>http://socket7.net/article/php-5-static-and-inheritance#comment-45</link>
  <author>KEM</author>
  <description>
    &lt;p&gt;this has been irking me for a while.&lt;/p&gt;
&lt;p&gt;anybody know if you can catch &quot;method undefined&quot; errors with set_error_handler? no luck yet... i'm not exactly sure what kind of error that is. it may not be &quot;catchable&quot;.&lt;/p&gt;
&lt;p&gt;dirty, but (hypothetically):&lt;/p&gt;
&lt;pre&gt;
&amp;lt;?php
	function myErrorHandler($errno, $errstr){
		$info = debug_backtrace();
		// if called on a subclass of Record, divert to a call to 
		// Table::find with the correct $table argument
	}
	set_error_handler(&amp;apos;myErrorHandler&amp;apos;);

	class Table {
		public static function find($table){
			// ...
		}
	}
	
	// dummy
	abstract class Record {}
	
	class Person extends Record {
		public static $table = &amp;apos;People&amp;apos;;
	}
	
	Person::find();

?&amp;gt;

&lt;/pre&gt;

&lt;p&gt;that would keep the classes nice and clean&amp;hellip;&lt;/p&gt;  </description>
  <guid isPermaLink="true">http://socket7.net/article/php-5-static-and-inheritance#comment-45</guid>
  <pubDate>Sat, 18 Aug 2007 20:34:31 -0700</pubDate>
</item>
  <item>
  <title>Re: My solution</title>
  <link>http://socket7.net/article/php-5-static-and-inheritance#comment-38</link>
  <author>Brett (http://socket7.net)</author>
  <description>
    I like your solution for its brevity.  I also like that for each new class it's only a small method to implement; it's very well contained. I've never liked my solution of passing variables around like a fool; that's incredibly messy.&lt;br /&gt;
&lt;br /&gt;
Thanks for sharing.  </description>
  <guid isPermaLink="true">http://socket7.net/article/php-5-static-and-inheritance#comment-38</guid>
  <pubDate>Sun, 15 Jul 2007 19:41:08 -0700</pubDate>
</item>
  <item>
  <title>My Solution</title>
  <link>http://socket7.net/article/php-5-static-and-inheritance#comment-37</link>
  <author>Tom Lancaster (http://www.newhanoian.com)</author>
  <description>
    &lt;pre&gt;
static $table;

 protected function table() {
	$vars = get_class_vars(get_class($this));
	return $vars['table'];
}
&lt;/pre&gt;  </description>
  <guid isPermaLink="true">http://socket7.net/article/php-5-static-and-inheritance#comment-37</guid>
  <pubDate>Wed, 11 Jul 2007 22:25:42 -0700</pubDate>
</item>
  <item>
  <title>Exactly the same problem</title>
  <link>http://socket7.net/article/php-5-static-and-inheritance#comment-33</link>
  <author>Jonovic</author>
  <description>
    This is realy pain in the a.. My solution for this time is to turn to dynamic objects and forget the static classes for a while. I have been working around the database access objects with the help of design patterns.  </description>
  <guid isPermaLink="true">http://socket7.net/article/php-5-static-and-inheritance#comment-33</guid>
  <pubDate>Mon, 09 Jul 2007 11:43:02 -0700</pubDate>
</item>
  <item>
  <title>Re: Workaround?</title>
  <link>http://socket7.net/article/php-5-static-and-inheritance#comment-19</link>
  <author>Brett (http://socket7.net)</author>
  <description>
    &lt;p&gt;I worked around it in two ways, neither of which are great.  One of the ways is to set a member variable in the constructor.  This makes the value available within the object as well as from the outside, though it is not static.  Obviously not a great solution.&lt;/p&gt;

&lt;p&gt;The second way I've worked around this is to pass an extra class name parameter into the static method calls telling the method which class it should 'act as.'  Again, not a great solution.&lt;/p&gt;

&lt;p&gt;If you're willing to put up with the lack of purity, these two options work well enough.  Hopefully some future version of PHP will address this.&lt;/p&gt;  </description>
  <guid isPermaLink="true">http://socket7.net/article/php-5-static-and-inheritance#comment-19</guid>
  <pubDate>Sat, 05 May 2007 14:54:34 -0700</pubDate>
</item>
  <item>
  <title>Workaround?</title>
  <link>http://socket7.net/article/php-5-static-and-inheritance#comment-18</link>
  <author>Tom Lancaster (http://www.newhanoian.com)</author>
  <description>
    &lt;p&gt;I'm having this exact same problem. In my case I'm subclassing  an abstract acts&lt;em&gt;as&lt;/em&gt;tree for different db tables. Of course I have the table name as a static member, and of course it doesn't work.&lt;/p&gt;

&lt;p&gt;I'm interested to know how you work around this.&lt;/p&gt;
  </description>
  <guid isPermaLink="true">http://socket7.net/article/php-5-static-and-inheritance#comment-18</guid>
  <pubDate>Wed, 02 May 2007 22:20:27 -0700</pubDate>
</item>

  </channel>
</rss>
<!-- 0.1211 -->