<?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>Mike Conley&#039;s Blog &#187; PHP</title>
	<atom:link href="http://mikeconley.ca/blog/category/technology/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://mikeconley.ca/blog</link>
	<description>The personal blog of a Toronto based graduate student, software developer, musician, and theatre enthusiast.</description>
	<lastBuildDate>Tue, 07 Sep 2010 21:11:39 +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>The Shoulders of Tall, Smart People</title>
		<link>http://mikeconley.ca/blog/2009/09/01/the-shoulders-of-tall-smart-people/</link>
		<comments>http://mikeconley.ca/blog/2009/09/01/the-shoulders-of-tall-smart-people/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 02:12:02 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Musings]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[8088XT IBM Clone]]></category>
		<category><![CDATA[Angelo Mottola]]></category>
		<category><![CDATA[asvisn]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[computers]]></category>
		<category><![CDATA[district school board of niagara]]></category>
		<category><![CDATA[doug mcquiggan]]></category>
		<category><![CDATA[Dr. Jim Clarke]]></category>
		<category><![CDATA[dsbn]]></category>
		<category><![CDATA[ECE]]></category>
		<category><![CDATA[greg wilson]]></category>
		<category><![CDATA[groovy concepts]]></category>
		<category><![CDATA[influences]]></category>
		<category><![CDATA[irc]]></category>
		<category><![CDATA[joel beck]]></category>
		<category><![CDATA[jong lee]]></category>
		<category><![CDATA[julian rabideau]]></category>
		<category><![CDATA[karen reid]]></category>
		<category><![CDATA[ken pidgen]]></category>
		<category><![CDATA[ken redekop]]></category>
		<category><![CDATA[lost]]></category>
		<category><![CDATA[Marcade]]></category>
		<category><![CDATA[markus project]]></category>
		<category><![CDATA[michael langlois]]></category>
		<category><![CDATA[mila shostak]]></category>
		<category><![CDATA[Necrolyte]]></category>
		<category><![CDATA[NeoZones]]></category>
		<category><![CDATA[nick braun]]></category>
		<category><![CDATA[Prof. Eric Hehner]]></category>
		<category><![CDATA[Prof. James McLean]]></category>
		<category><![CDATA[Prof. John Carter]]></category>
		<category><![CDATA[Prof. Tarak Abdelrahman]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[QB]]></category>
		<category><![CDATA[QB4.5]]></category>
		<category><![CDATA[QuickBasic]]></category>
		<category><![CDATA[quote notation]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Tek]]></category>
		<category><![CDATA[T_S]]></category>
		<category><![CDATA[university of toronto]]></category>
		<category><![CDATA[uoft]]></category>

		<guid isPermaLink="false">http://mikeconley.ca/blog/?p=666</guid>
		<description><![CDATA[Recently, I came to the realization that I&#8217;ve been writing computer programs in one form or another since I was about 6 or 7 years old. Along the way, I&#8217;ve had plenty of people to influence the way I think about code, and how I write it.  Sure, there have been plenty of textbooks along [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I came to the realization that I&#8217;ve been writing computer programs in one form or another since I was about 6 or 7 years old.</p>
<p>Along the way, I&#8217;ve had plenty of people to influence the way I think about code, and how I write it.  Sure, there have been plenty of textbooks along the way too, but I want to give some thanks to the <em>people </em>who have directly affected my abilities to do what I do.</p>
<p>And what better way of doing that then by listing them?</p>
<h2>A Chronological List of People Who Have Influenced My Coding</h2>
<ol>
<li>My parents, for bringing home our first family computer.  It was an <a href="http://en.wikipedia.org/wiki/IBM_Personal_Computer_XT">8088XT IBM Clone</a> &#8211; no hard drive, 640K of RAM, dual 5 1/4 floppies&#8230;it was awesome.  This is the computer I started coding on &#8211; but I couldn&#8217;t have started without&#8230;</li>
<li>My Uncle Mark and my Aunt Soo.  Both have degrees in Computer Science from the University of Waterloo (that&#8217;s where they met).  My recollection is pretty vague, but I&#8217;m pretty sure that a lot of the programming texts in my house (a big blue QuickBasic manual comes to mind) surely didn&#8217;t come from my parents &#8211; must have been those two.  With the book in one hand, and the 8088 in the other, I cranked out stupid little programs, little text adventure games, quizzes, etc.</li>
<li>The online QB community from the late 1990&#8242;s to the early 2000&#8242;s.  When my family got online, I soon found myself hanging out at <a href="http://web.archive.org/web/20000407190211/http://www.neozones.com/">NeoZones</a>, in the #quickbasic IRC channel on EFNet&#8230; actually, a lot of crazy stuff was being done with QuickBasic back then &#8211; I remember when <a href="http://www.phatcode.net/downloads.php?id=202">DirectQB</a> came out, and somebody was able to code a raytracer&#8230;in BASIC.  It was awesome.  I&#8217;d say these were my foundation years, when I learned all of my programming fundamentals.</li>
<li>My friends Nick Braun, Joel Beck, and Doug McQuiggan &#8211; these three guys and I used to come up with crazy ideas for games, and I&#8217;d try to program them.  I&#8217;d come home from school, and pound out code for a computer game for a few hours in the basement.  More often then not, these projects would simply be abandoned, but still, a lot was learned here.<br />
Joel, Doug, our friend Julian and myself were also members of a band in highschool.  It was my job to build and maintain the band website, and this is when I learned to write HTML, basic Perl, and simple JavaScript.</li>
<li>After highschool, I went into Electrical and Computer Engineering at the University of Toronto.  I didn&#8217;t do too well at the Electrical bits, but I could handle myself at the Computer bits.  I learned OOP, Java, and basic design patterns from <a href="http://www.wjamesmaclean.net/">Prof. James McLean</a>.</li>
<li>I also learned a great deal from Prof. McLean&#8217;s course text &#8211; Introduction to Computer Science Using Java by <a href="http://www.ecf.utoronto.ca/~jcarter/">Prof. John Carter</a>.  I know I said I wasn&#8217;t going to mention textbooks, but I also got taught Discrete Mathematics from Prof. Carter, so I thought I&#8217;d toss him in too.</li>
<li>My second (and last) semester in ECE had me taking Programming Fundamentals with <a href="http://www.eecg.toronto.edu/~tsa/">Prof. Tarak Abdelrahman</a>.  I learned basic C++ from Prof. Abdelrahman, and how to deal with large systems of code.</li>
<li>After my move to the Arts &amp; Science Faculty, I took my first Computer Science course with <a href="http://www.cs.utoronto.ca/~clarke/">Dr. Jim Clarke.</a> I learned about Unit Testing, and more design patterns.  I also eventually learned some basic Python from him, but I think it was in another course.</li>
<li>I took CSC258 with <a href="http://www.cs.toronto.edu/~hehner/">Prof. Eric Hehner</a>, and learned about the structure of computer processors.  Physically, this was a low-level as I&#8217;d ever gotten to computers.  I was familiar with writing Assembly from my QB days, but Prof. Hehner&#8217;s Opcode exercises were really quite challenging &#8211; in a pleasant way.  Also, check out his concept of <a href="http://en.wikipedia.org/wiki/Quote_notation">Quote Notation</a>&#8230;</li>
<li>After that year, I spent the first of three summers working for the <a href="http://www.dsbn.edu.on.ca">District School Board of Niagara</a>.  Ken Pidgen was my manager, Mila Shostak was my supervisor.  Ken gave me incredible freedom to work, and soon I was developing web applications, as opposed to just fixing up department websites (as I originally thought I would be doing).  Mila gave me guidance, and showed me how to use CSS to style a website.  She also got me started using PHP and MySQL to create basic web applications.</li>
<li>While working at the Board, I had the pleasure of sitting across from Jong Lee.  Jong and I would bounce ideas off of one another when we&#8217;d get stuck on a programming problem.  He was very experienced, and I learned lots of practical programming techniques from him.</li>
<li>Michael Langlois and Ken Redekop acted as my clients at the Board, and always gave me interesting jobs and challenges to perform.Everyone at the Board was always very positive with me, and I&#8217;ll always be grateful that they took a newbie undergrad under their wing!  I was given a ridiculous amount of freedom at the Board, and was allowed to experiment with various technologies to get the job done.  Through my three summers there, I learned bits about Rails, CakePHP, MVC, network security, how to deploy an application remotely, how to run a local server, how to develop locally and post to remote, ORM, Flash, web security&#8230;so many things.  The list is huge.</li>
<li><a href="http://www.cs.toronto.edu/~reid/">Karen Reid</a> and <a href="http://www.cs.toronto.edu/~gvwilson/">Greg Wilson</a> have been the latest influences on me.  The MarkUs Project was the first project I&#8217;ve ever worked on with a team.  It was my first time seriously using version control, my first time using a project management portal (Dr. Project), my first time learning Ruby, and my first time working on an open source project.  I&#8217;ve also learned plenty about time management, people, the business of software, and how to get things done.  Again, I&#8217;ve been given lots of freedom to learn, experiment, and hone my craft.</li>
</ol>
<p>Anyhow, these are the people who come to mind.  I might add to this list if I remember anyone else.</p>
<p>But in the mean time, for the people listed above:  thank you.</p>
]]></content:encoded>
			<wfw:commentRss>http://mikeconley.ca/blog/2009/09/01/the-shoulders-of-tall-smart-people/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My Web App in the News</title>
		<link>http://mikeconley.ca/blog/2009/03/28/my-web-app-in-the-news/</link>
		<comments>http://mikeconley.ca/blog/2009/03/28/my-web-app-in-the-news/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 19:25:31 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[auction]]></category>
		<category><![CDATA[dsbn]]></category>
		<category><![CDATA[gsoa]]></category>
		<category><![CDATA[mvc]]></category>

		<guid isPermaLink="false">http://mikeconley.ca/blog/?p=341</guid>
		<description><![CDATA[ANOTHER UPDATE: Whoops.  Fixed the links to the auction and the St. Catharines Standard article. UPDATE: Apparently, the Feds are getting in on the online auction circuit too. Over the past three summers, I&#8217;ve been employed by the District School Board of Niagara as an internal web application developer. One of my first jobs in [...]]]></description>
			<content:encoded><![CDATA[<p><strong>ANOTHER UPDATE:</strong> Whoops.  Fixed the links to the auction and the St. Catharines Standard article.</p>
<p><strong>UPDATE: </strong><a href="http://www.stcatharinesstandard.ca/ArticleDisplay.aspx?e=1490637"> Apparently, the Feds are getting in on the online auction circuit too. </a></p>
<p>Over the past three summers, I&#8217;ve been employed by the District School Board of Niagara as an internal web application developer.</p>
<p>One of my first jobs in the summer of 2006 was to rebuild the online auction application that the DSBN Purchasing department ran.  The original auction let the Board dispose of old equipment quickly and easily, and was quite popular.  Unfortunately, it was also written in (almost) unintelligible/unmaintainable Perl.</p>
<p>So I rewrote it by myself, and learned PHP/MSSQL along the way.  We called this new auction site The Government Surplus Online Auction, and we opened it up so that other government agencies could also post items for auction.</p>
<p>Things went along fine until last summer, when the site got attacked by an SQL Injection bot.  Back in 2006, I had no idea what SQL injection was, or how to guard myself.</p>
<p>So there I am &#8211; I&#8217;ve just come back from a camping trip, my inbox is packed with complaints, and I&#8217;ve got three weeks until school begins.  Crap.</p>
<p>Luckily, I had plenty of tools at my disposal.  My web app development skills and practices had evolved dramatically since 2006, and I had been itching to reimplement the auction anyhow.  The SQL Injection attack was a perfect excuse for me to gut the entire application, and rebuild from scratch.</p>
<p>And I did.  I rebuilt the whole thing from the ground up in three weeks.  It&#8217;s been almost a year since it was deployed, and I&#8217;m still very happy with its performance, and the code that runs it.</p>
<p>I&#8217;m <strong>not </strong>happy with its overall UI design.  I think there are plenty of improvements to be made in that regard.  Luckily, it&#8217;s coded using a light <a href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller">MVC</a> framework that I designed/built myself, so reskinning shouldn&#8217;t be too hard for whoever decides to work on it&#8230;</p>
<p>Apparently, I&#8217;m not the only one happy with the auction site.  <a href="http://www.stcatharinesstandard.ca/ArticleDisplay.aspx?e=1476981">Check out this article (now without annoying print dialog).</a></p>
<p>I just checked the logs today &#8211; we hit a new record: an aerial truck went for $22,000 dollars.  With the Board receiving 5% ($1100) of that simply for hosting, I think everybody is walking away happy.</p>
<p><a href="http://www.dsbn.edu.on.ca/purchasing/gsoa">Here&#8217;s the auction.</a></p>
<p>Proof that I wrote it?  <a href="http://www.dsbn.edu.on.ca/purchasing/gsoa/CREDITS.txt">This&#8217;ll have to do.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mikeconley.ca/blog/2009/03/28/my-web-app-in-the-news/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Injection Prevention in PHP &#8211; Tip 1</title>
		<link>http://mikeconley.ca/blog/2009/02/18/sql-injection-prevention-in-php-tip-1/</link>
		<comments>http://mikeconley.ca/blog/2009/02/18/sql-injection-prevention-in-php-tip-1/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 21:36:38 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sql injection]]></category>
		<category><![CDATA[web applications]]></category>

		<guid isPermaLink="false">http://mikeconley.ca/blog/?p=157</guid>
		<description><![CDATA[It&#8217;s amazing &#8211; I&#8217;ve been going around, Googling for anything with &#8220;index.php?id=&#8221;&#8230;and that&#8217;s really all it takes.  Now, granted, SQL Injection isn&#8217;t new, and a lot of the top hits have taken some steps to protect themselves, but if you go deep &#8211; like, Google search page 23 deep &#8211; you&#8217;ll find ones that break [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s amazing &#8211; I&#8217;ve been going around, Googling for anything with &#8220;index.php?id=&#8221;&#8230;and that&#8217;s really all it takes.  Now, granted, SQL Injection isn&#8217;t new, and a lot of the top hits have taken some steps to protect themselves, but if you go deep &#8211; like, Google search page 23 deep &#8211; you&#8217;ll find ones that break if you put a semi-colon after the id # &#8211; and if it breaks, it&#8217;s vulnerable.</p>
<p>So, here&#8217;s my first tip on preventing SQL Injection &#8211; when you&#8217;re asking for an ID number, make sure it&#8217;s a number, and nothing else.  Also consider using prepared statements &#8211; database wrappers like <a href="http://pear.php.net/package/MDB2">MDB2</a> for PHP make this easy.</p>
<p>Check this out &#8211; this might be how I would have done it 3 years ago:</p>
<pre>&lt;?php
  //Assume we're already connected to a MySQL database...
  $id = $_GET['id'];

  $result = mysql_query('SELECT * from pages where id='.$id);
  if (!$result) {
     die('Invalid query: ' . mysql_error());
  }
  ... //Code to print out my result to the page
?&gt;</pre>
<p>I&#8217;d do it this way now:</p>
<p><strong>Note:</strong> My use of MDB2 might be a little rusty &#8211; I haven&#8217;t tested this code, and I usually compose RowDataGateway objects with MDB2 to represent my data.  So pay more attention to the structure than the actual syntax.</p>
<pre>&lt;?php
  require 'View.php';
  require 'MDB2.php';  //An excellent DB layer from the PEAR libs

  //Code to set $mdb2 as our DB connection variable
  //See http://pear.php.net/package/MDB2 for details
  $id = $_GET['id'];

  try {
    if(!is_int($id)) {
      //ID wasn't an int, it's no good, let's bail
      throw new Exception('Could not recognize the id that you passed');
    }
    //ID was an int, let's see if we can find the record
    $sql = 'SELECT * from pages where id=:id";
    $statement = $mdb2-&gt;prepare($sql);
    $statement-&gt;bindParam('id', $id);
    $result = $statement-&gt;execute();
    if(PEAR::isError($result)) {
      //Uh oh - our result was an error on the PEAR library level
      throw new Exception('There was an error communicating with the database');
    }
    //Insert the database result into the view, render, and die.
    $content = new View('templates/page.tpl', array('page' =&gt; $result-&gt;fetchOne()));
    $content-&gt;render();
    die;
  }
  catch(Exception $e) {
    //We must have caught an exception - put this into our
    //error page template with the error message, render, die.
    $content = new View('templates/error.tpl', array('message' =&gt; $e-&gt;getMessage()));
    $content-&gt;render();
    die;
  }
?&gt;</pre>
<p>Yes, it&#8217;s quite a bit more code.  But I feel safer just looking at it.<br />
Did I miss anything on this?  Please post a comment if you  notice that I&#8217;ve left a gaping hole.  Learning is good.</p>
]]></content:encoded>
			<wfw:commentRss>http://mikeconley.ca/blog/2009/02/18/sql-injection-prevention-in-php-tip-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preventing SQL Injection Attacks</title>
		<link>http://mikeconley.ca/blog/2009/02/16/preventing-sql-injection-attacks/</link>
		<comments>http://mikeconley.ca/blog/2009/02/16/preventing-sql-injection-attacks/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 18:48:04 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sql injection]]></category>
		<category><![CDATA[web applications]]></category>

		<guid isPermaLink="false">http://mikeconley.ca/blog/?p=125</guid>
		<description><![CDATA[Over the reading week, along with studying for various midterms and assignments, I&#8217;ve decided to brush up on preventing SQL Injection attacks in web applications. Pretty scary/awesome stuff out there on this stuff.  Here&#8217;s a great place to get some SQL Injection training, and here&#8217;s an excellent SQL Injection cheat sheet. I got hit with [...]]]></description>
			<content:encoded><![CDATA[<p>Over the reading week, along with studying for various midterms and assignments, I&#8217;ve decided to brush up on preventing SQL Injection attacks in web applications.</p>
<p>Pretty scary/awesome stuff out there on this stuff.  <a href="http://www.hackthissite.org" target="_self">Here&#8217;s a great place to get some SQL Injection training</a>, and <a href="http://ferruh.mavituna.com/sql-injection-cheatsheet-oku/" target="_self">here&#8217;s an excellent SQL Injection cheat sheet</a>.</p>
<p>I got hit with a pretty bad SQL Injection attack last summer on an application I had written 3 years ago (before I had any clue that SQL Injection attacks were possible).</p>
<p>Here&#8217;s the take home message:  <strong>never trust user input.  Ever. </strong>If you&#8217;re expecting an int, make sure it&#8217;s an int.  <strong>Never insert user input directly into an SQL string.</strong> Use prepared statements instead, or stored procedures.</p>
<p>Luckily, I just did a quick survey of all of my running apps, and I seem to be OK in terms of SQL Injection.  Still, it&#8217;s a common attack vector &#8211; and the consequences of being lazy on user input can be pretty awful.</p>
<p><strong>Update: </strong> Want to see something awesome?  <a href="http://www.milw0rm.com/video/watch.php?id=92" target="_self">Check this out &#8211; a Debian box gets rooted through MySQL injection&#8230;killer soundtrack too.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mikeconley.ca/blog/2009/02/16/preventing-sql-injection-attacks/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Model-View-Controller in PHP:  Model</title>
		<link>http://mikeconley.ca/blog/2009/02/13/model-view-controller-in-php-model/</link>
		<comments>http://mikeconley.ca/blog/2009/02/13/model-view-controller-in-php-model/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 16:34:19 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[late static binding]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[model-view-controller]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[rowdatagateway]]></category>

		<guid isPermaLink="false">http://mikeconley.ca/blog/?p=93</guid>
		<description><![CDATA[(Notes: the code here has been taken directly from the PHP Late Static Binding documentation if you want a more verbose and thorough explanation of this problem, check this out ) I have one thing to say for all of those PHP developers who look at Rails&#8217; ActiveRecord class and get all excited about implementing [...]]]></description>
			<content:encoded><![CDATA[<p>(Notes:</p>
<ul>
<li>the code here has been taken directly from the <a href="http://ca2.php.net/oop5.late-static-bindings" target="_self">PHP Late Static Binding documentation</a></li>
<li>if you want a more verbose and thorough explanation of this problem, <a href="http://www.actsasflinn.com/trackbacks?article_id=php-and-activerecord&amp;day=08&amp;month=08&amp;year=2007 " target="_self">check this out</a></li>
</ul>
<p>)</p>
<p>I have one thing to say for all of those PHP developers who look at Rails&#8217; ActiveRecord class and get all excited about implementing it in PHP:</p>
<p>It can&#8217;t be done.  Yet.</p>
<p>Here&#8217;s why:</p>
<p>Until PHP5.3, PHP does not implement a feature called &#8220;late static binding&#8221;.  What is late static binding?  Well, how about I show you what it&#8217;s like to NOT have late static binding:</p>
<pre>class A {
   public static function who() {
     echo __CLASS__;
   }
   public static function test() {
     self::who();
  }
}
class B extends A {
  public static function who() {
    echo __CLASS__;
  }
}
B::test();  //Outputs:  'A'</pre>
<p>That&#8217;s right:  B::test() outputs &#8216;A&#8217;.  This is a problem, because while it is true that B is a subclass of A, B is still B.  When I call a static method of B, I want it to know that it&#8217;s B.</p>
<p>With late static binding (only available in PHp5.3 and onward), this goes away:</p>
<pre>&lt;?php
class A {
  public static function who() {
    echo __CLASS__;
  }
  public static function test() {
    static::who(); // Here comes Late Static Bindings
  }
}
class B extends A {
  public static function who() {
    echo __CLASS__;
  }
}
B::test();  //Outputs 'B'
?&gt;</pre>
<p>Why is this a problem for ActiveRecord?  Well, say we define a class called ActiveRecord, and create a subclass of ActiveRecord called Person.  When I call Person::find_all(), PHP5.2 is going to run find_all in ActiveRecord &#8211; and ActiveRecord&#8217;s find_all() will not know what kind of subclass I am.  It won&#8217;t know if I&#8217;m a Person, Dog, Pizza, or any of that jazz.  Essentially, ActiveRecord is now dead in the water.</p>
<p>Now, you could just make find_all a standard method instead of a static one, but then for every find operation, you&#8217;d have to do this:</p>
<pre>$p = new Person();
$persons = $p-&gt;find_all();</pre>
<p>Semantically, this doesn&#8217;t make much sense.</p>
<p><em>But, PHP coders, take heart -  there are two silver linings:</em></p>
<ul>
<li>PHP5.3 has late static bindings!  As soon as it&#8217;s released, rejoice, and implement ActiveRecord</li>
<li><a href="http://www.actsasflinn.com/2007/08/08/php-and-activerecord" target="_self">There&#8217;s always RowDataGateway!</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://mikeconley.ca/blog/2009/02/13/model-view-controller-in-php-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Model-View-Controller in PHP:  View</title>
		<link>http://mikeconley.ca/blog/2009/02/09/model-view-controller-in-php/</link>
		<comments>http://mikeconley.ca/blog/2009/02/09/model-view-controller-in-php/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 02:25:36 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[model-view-controller]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[views]]></category>

		<guid isPermaLink="false">http://mikeconley.ca/blog/?p=37</guid>
		<description><![CDATA[I&#8217;ve been programming in PHP for a few years now, and after being exposed to MVC through Ruby on Rails back in 2007, I came to realize that I liked the idea of keeping the presentation of data separate from the manipulation of data. So I built a View class.  Download View Class Usage: $view [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been programming in PHP for a few years now, and after being exposed to MVC through Ruby on Rails back in 2007, I came to realize that I liked the idea of keeping the presentation of data separate from the manipulation of data.</p>
<p>So I built a View class.  <a href="http://mikeconley.ca/blog/wp-content/uploads/2009/02/viewclass.phps">Download View Class</a></p>
<p>Usage:</p>
<pre>$view = new View('views/main_page.tpl', array(
       'some_var' =&gt; 'This will be assigned to $some_var in the view'));
$view-&gt;render();</pre>
<p>And like that, data presentation is separated from data manipulation.</p>
<p>Piece of cake.</p>
]]></content:encoded>
			<wfw:commentRss>http://mikeconley.ca/blog/2009/02/09/model-view-controller-in-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
