<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Generation 5 &#187; Server Frameworks</title>
	<atom:link href="http://gen5.info/q/category/tools/server-frameworks/feed/" rel="self" type="application/rss+xml" />
	<link>http://gen5.info/q</link>
	<description>Towards Intelligent Systems</description>
	<lastBuildDate>Fri, 20 Aug 2010 19:43:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Embrace Dynamic PHP</title>
		<link>http://gen5.info/q/2008/04/24/embrace-dynamic-php/</link>
		<comments>http://gen5.info/q/2008/04/24/embrace-dynamic-php/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 14:44:01 +0000</pubDate>
		<dc:creator>Paul Houle</dc:creator>
				<category><![CDATA[CRUD]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server Frameworks]]></category>

		<guid isPermaLink="false">http://gen5.info/q/2008/04/24/embrace-dynamic-php/</guid>
		<description><![CDATA[Mat Byrne recently posted source code for a dynamic domain object in PHP which takes advantage of the dynamic nature of PHP.  It&#8217;s a good example of how programmers can take advantage of the unique characteristics of a programming language. Statically typed languages such as C# and Java have some advantages:  they run faster and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://matbyrne.com/">Mat Byrne</a> recently posted source code for a <a href="http://matbyrne.com/2008/4/20/dynamic-domain-objects-in-php">dynamic domain object in PHP</a> which takes advantage of the dynamic nature of PHP.  It&#8217;s a good example of how programmers can take advantage of the unique characteristics of a programming language.</p>
<p>Statically typed languages such as C# and Java have some advantages:  they run faster and IDE&#8217;s can understand the code enough to save typing (with your fingers),  help you refactor your code,  and help you fix errors.  Although there&#8217;s a lot of things I like <a href="http://">symfony</a>,  it feels like a Java framework that&#8217;s invaded the PHP world.  Eclipse would help you deal with the endless getters and setters and domain object methods with 40-character names in Java,  Eclipse.</p>
<p>The limits of polymorphism are a serious weakness of today&#8217;s statically typed languages.  C# and Java apps that I work with are filled with if-then-else or case ladders when they need to initialize a dynamically chosen instance of one of a set of classes that subclass a particular base class or that implement a particular interface.  Sure,  you can make a HashMap or Dictionary that&#8217;s filled with Factory objects,  but any answer for that is cumbersome.  In PHP,  however,  you can write</p>
<pre>$class_name="Plugin_Module_{$plugin_name}";
$instance = new $class_name($parameters);</pre>
<p>This is one of several patterns which make it possible to implement simple but powerful frameworks in PHP.</p>
<p>Mat,  on the other hand,  uses the &#8216;magic&#8217; __call() method to implement get and set methods dynamically.  This makes it possible to &#8216;implement&#8217; getters and setters dynamically by simply populating a list of variables,  and drastically simplifies the construction and maintainance of domain objects.  A commenter suggests that he go a step further and use the __get() and __set() method to implement properties.  It&#8217;s quite possible to implement active records in PHP with a syntax like</p>
<pre>$myTable = $db-&gt;myTable;
$row = $myTable-&gt;fetch($primaryKey);
$row-&gt;Name="A New Name";
$row-&gt;AccessCount = $row-&gt;AccessCount+1;
$row-&gt;save();</pre>
<p>I&#8217;ve got an experimental active record class that introspects the database (no configuration file!) and implements exactly the above syntax,  but it currently doesn&#8217;t know anything about joins and relationships.  It would be a great day for PHP to have a database abstraction that is (i) mature,  (ii) feels like PHP,  and (iii) solves (or reduces) the two-artifact problem of maintaining both a database schema AND a set of configuration files that control the active record layer.</p>
<p>The point of this post isn&#8217;t that dynamically typed languages are better than statically typed languages,  but rather that programmers should make the most of the features of the language they use:  no PHP framework has become the &#8216;rails&#8217; of PHP because no PHP framework has made the most of the dynamic natures of the PHP language.</p>
]]></content:encoded>
			<wfw:commentRss>http://gen5.info/q/2008/04/24/embrace-dynamic-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
