<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Debuggery</title>
	<atom:link href="http://debuggery.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://debuggery.net</link>
	<description>Code matters</description>
	<lastBuildDate>Fri, 12 Aug 2011 19:42:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='debuggery.net' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/bac615fe3a9f296cf4491f16f5caf93e?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Debuggery</title>
		<link>http://debuggery.net</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://debuggery.net/osd.xml" title="Debuggery" />
	<atom:link rel='hub' href='http://debuggery.net/?pushpress=hub'/>
		<item>
		<title>What&#8217;s up with Getters and Setters?</title>
		<link>http://debuggery.net/2010/09/27/whats-up-with-getters-and-setters/</link>
		<comments>http://debuggery.net/2010/09/27/whats-up-with-getters-and-setters/#comments</comments>
		<pubDate>Mon, 27 Sep 2010 12:50:04 +0000</pubDate>
		<dc:creator>Bryan</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://debuggery.net/?p=68</guid>
		<description><![CDATA[I&#8217;ve been following Vic Cherubini&#8216;s series on Zend Developer Zone about his ORM &#8220;DataModeler,&#8221; mostly to get some insight in to another programmer&#8217;s ORM design decisions, as well as to see if he had any nifty ideas I could appropriate for SmartObjects. All in all, I think DataModeler is an interesting project. It&#8217;s definitely a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debuggery.net&amp;blog=26135019&amp;post=68&amp;subd=debuggery&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been following <a href="http://leftnode.com/" target="_blank">Vic Cherubini</a>&#8216;s <a href="http://devzone.zend.com/article/12511-DataModeler-Simple-ORM---Part-1-Models" target="_blank">series</a> on <a href="http://devzone.zend.com" target="_blank">Zend Developer Zone</a> about his ORM &#8220;<a href="http://github.com/leftnode/DataModeler" target="_blank">DataModeler</a>,&#8221; mostly to get some insight in to another programmer&#8217;s ORM design decisions, as well as to see if he had any nifty ideas I could appropriate for <a href="http://github.com/bpjohnson/anApp5/tree/master/lib/smartObjects/" target="_blank">SmartObjects</a>. <span id="more-68"></span>All in all, I think DataModeler is an interesting project. It&#8217;s definitely a lot simpler to set up than most other ORMs, but there&#8217;s one thing Vic does that confuses me:</p>
<p>[codesyntax lang="php"]</p>
<pre>&lt;?php
//previously, User was defined as a DataModeller Model

$user = new User;
$user-&gt;setName('Vic Cherubini')
  -&gt;setAge(26)
  -&gt;setHeight(74)
  -&gt;setJobTitle('Software Mechanic');

?&gt;</pre>
<p>[/codesyntax]</p>
<p>That&#8217;s right, it uses setters, and for the love of me, I can&#8217;t figure out why. Getters and setters, for the unaware, are something some other programming languages use to get at variables on an object. They aren&#8217;t required in PHP. The two most common reasons for using them in PHP are:</p>
<ol>
<li>It allows users to set the value of private variables.</li>
<li>It allows the programmer to enforce some sanity checking on the variables when they&#8217;re set.</li>
</ol>
<p>As for the former argument, I have no idea why you&#8217;d want to allow someone to modify a private variable and yet not make that variable public or protected instead. Maybe I&#8217;m missing something but that seems rather silly to me.</p>
<p>The latter argument carries a lot more weight. We all love our data integrity, for sure. But PHP provides two magic methods ( <em>__get()</em> and <em>__set()</em> ) that let you override how variables are handled by your objects. Why you wouldn&#8217;t use those&#8230; Just compare these two objects:</p>
<p>[codesyntax lang="php"]</p>
<p>&lt;?php</p>
<pre>class foo {
   private $bar;
   public function setBar($value) {
   	$this-&gt;bar = $value; //sanity checking here.
   }
   public function getBar($value) {
   	return $this-&gt;bar;
   }
}

class ding {
	public function __set($name, $value) {
		$this-&gt;$name = $value;
	}
	public function __get($name) {
		return $this-&gt;$name;
	}
}
?&gt;
[/codesyntax]</pre>
<p>Footprint-wise they&#8217;re pretty similar. You could add doc strings to foo-&gt;bar, and not to ding-&gt;bat but all in all fairly even. It&#8217;s the person using your object that&#8217;ll have a slightly easier time of it:</p>
<p>[codesyntax lang="php"]</p>
<pre>&lt;?php
//which do you like better?
$foo = new foo();
$foo-&gt;setBar('high');

$ding = new ding();
$ding-&gt;bat = "Edith Bunker";
?&gt;</pre>
<p>[/codesyntax]</p>
<p>I suppose at this point it&#8217;s six of one, a half dozen of the other. However, if you have a lot of properties and are trying to keep things <a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY</a>, there&#8217;s a clear winner:</p>
<p>[codesyntax lang="php"]</p>
<pre>&lt;?php

class foo {
   private $bar;
   private $bar2;
   private $bar3;
   private $bar4;
   private $bar5;

   public function setBar($value) {
   	$this-&gt;bar = $value; //sanity checking here.
   }
   public function getBar($value) {
   	return $this-&gt;bar;
   }
   public function setBar2($value) {
   	$this-&gt;bar2 = $value; //sanity checking here.
   }
   public function getBar2($value) {
   	return $this-&gt;bar2;
   }
   public function setBar3($value) {
   	$this-&gt;bar3 = $value; //sanity checking here.
   }
   public function getBar3($value) {
   	return $this-&gt;bar3;
   }
   public function setBar4($value) {
   	$this-&gt;bar4 = $value; //sanity checking here.
   }
   public function getBar4($value) {
   	return $this-&gt;bar4;
   }

}

class ding {
	public function __set($name, $value) {
		$this-&gt;$name = $value;
	}
	public function __get($name) {
		return $this-&gt;$name;
	}
}
?&gt;</pre>
<p>[/codesyntax]</p>
<p>So what if you want to have the utility of sanity checking your variables and phpDocumenting them, while retaining the clean and simple style of our magic methods? Well, you could put your data checks in the __set method, but that can get hairy if you&#8217;ve got a lot of variables:</p>
<p>[codesyntax lang="php"]</p>
<pre>&lt;?php

class ding {
	public function __set($name, $value) {
		if ($name == 'foo' &amp;&amp; is_int($value)) {
			$this-&gt;foo = $value;
		} else if ($name == 'bar' &amp;&amp; is_array($value)) {
			$this-&gt;bar = $value;
		} else if ($name == 'bat' &amp;&amp; $value == 'Edith Bunker') {
			$this-&gt;bat = TRUE;
		}
	}
}
?&gt;</pre>
<p>[/codesyntax]</p>
<p>A better solution would be to write validator methods per data type, then suss out which type the variable being set is supposed to be, and then validate it. This looks like a job for Reflection!</p>
<p>[codesyntax lang="php"]</p>
<pre>&lt;?php
abstract class validateMe {
  protected $variableValidations;

  public function __construct() {
    if (!is_array($this-&gt;variableValidations)) {
      $this-&gt;variableValidations = $this-&gt;_getValidations();
    }
  }

  public function __set($name, $value) {
    $newName = '_'.$name;
    if ($this-&gt;_validate($newName, $value)) {
      $this-&gt;$newName = $value;
    }
  }

  public function __get($name) {
    $newName = '_'.$name;
    return $this-&gt;$newName;
  }

  protected function _validate($name, $value) {
    if (isset($this-&gt;variableValidations[$name])) {
      $validator = $this-&gt;variableValidations[$name];
      $method = $validator['type'].'Validate';
      return $this-&gt;$method($value, $validator);
    }
    return TRUE; // or FALSE if you don't want to save any variables that don't have defined validations.
  } // end _validate()

  private function _getValidations() {
    $ref = new ReflectionClass(get_class($this));
    $props = $ref-&gt;getProperties();
    $retval = array();
    foreach ($props as $prop) {
      $name = $prop-&gt;getName();
      $varType = "unknown";
      $optional = FALSE;
      $args = "";
      $doc = explode("\n",$prop-&gt;getDocComment());
      foreach ($doc as $docLine) {
        if (preg_match('/\@var\s+([A-Za-z0-9]+)\s*(.*)/', $docLine, $matches)) {
          $varType = $matches[1];
          if (preg_match('/\[optional\]\s*(.*)/', $matches[2], $submatches)) {
            $optional = TRUE;
            $args = $submatches[1];
          } else {
            $args = $matches[2];
          }
        }
      }
      $retval[$name] = array(
        'type' =&gt; $varType,
        'optional' =&gt; $optional,
        'args' =&gt; $args
      );
    }
    return $retval;
  } // end _getValidations()

}
?&gt;</pre>
<p>[/codesyntax]</p>
<p>Well, that&#8217;s nice and all, but what does it do? First, it lets you declare class properties as <em>_propertyName</em> but access them as <em>propertyName</em>. With proper doc strings, you get validation! Just write methods called &lt;datatype&gt;Validate (eg. stringValidate) and you&#8217;re off to the races.  Here&#8217;s an example class that extends the abstract validateMe:</p>
<p>[codesyntax lang="php"]</p>
<pre>&lt;?php
class ding extends validateMe {
  /**
   * @var array Array of options
   */
  $_options = array();

  /**
   * @var boolean [optional] Is this person a dingbat?
   */
  $_bat;

  /**
   * @var int between 10 and 100
   */
  $_number;

  public function arrayValidate($value, $options) {
    return is_array($value) || $options['optional'];
  }

  public function booleanValidate($value, $options) {
    switch ($var) {
      case $var == TRUE:
      case $var == 1:
      case strtolower($var) == 'true':
      case strtolower($var) == 'on':
      case strtolower($var) == 'yes':
      case strtolower($var) == 'y':
        $out = TRUE;
        break;
      default: $out = FALSE;
    }

    return $out || $options['optional'];
  }

  public function intValidate($value, $options) {
    if (preg_match('/between\s*(\d+)and\s*(\d+)/i', $options['args'], $matches)) {
      if (is_numeric($value)) {
        if ((int)$value == $value) {
          return ($matches[1] &lt;= $value &amp;&amp; $value &lt;= $matches[2]) || $options['optional']; // is it between?
        } else {
          return FALSE || $options['optional']; // numeric, but not an integer
        }
      } else {
        return FALSE || $options['optional']; // not numeric
      }
    } else {
        return (is_numeric($value) &amp;&amp; ((int)$value == $value)) || $options['optional'];
    }
  }
}
?&gt;</pre>
<p>[/codesyntax]</p>
<p>Now in this case, this isn&#8217;t any less verbose than the getter/setter alternative would be. But this is an example to show how crazy you could get. Here&#8217;s a more real world example, a user object:</p>
<p>[codesyntax lang="php"]</p>
<pre>&lt;?php
class user extends validateMe {
  /**
   * @var string /^[A-Za-z0-9_-]+$/ User name, alphanumerics - and _ are allowed.
   */
  private $_username;
  /**
   * @var string /^[A-Za-z]+$/ Last name, alpha allowed.
   */
  private $_surname;
  /**
   * @var string /^[A-Za-z]+$/ First name, alpha allowed.
   */
  private $_givenname;
  /**
   * @var string /^\d{3}[-]*\d{2}[-]*\d{4}$/ Social Security Number
   */
  private $_ssn;  public function stringValidate($value, $options) {
    if (preg_match('/(\/[^\/]+\/).*/', $options['args'], $matches)) {
      // we have a regex
      return (is_string($value) &amp;&amp; preg_match($matches[1], $value)) || $options['optional'];
    } else {
      return is_string($value) || $options['optional'];
    }
  }
}
?&gt;</pre>
<p>[/codesyntax]</p>
<p>And you&#8217;ve validated and documented all of your variables, without writing individual getter/setter functions for each. Mmm&#8230; That&#8217;s a spicy meatball!</p>
<p>This is actually pretty close to how the new anObject is going to work. SmartObjects, though, are getting a super fancy validation plugin that does this, and also will check the DB structure for validity. &#8220;DESCRIBE `tablename`&#8221; anyone?</p>
<br />Filed under: <a href='http://debuggery.net/category/code/'>Code</a>, <a href='http://debuggery.net/category/code/php/'>PHP</a> Tagged: <a href='http://debuggery.net/tag/php5/'>php</a>, <a href='http://debuggery.net/tag/programming/'>Programming</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/debuggery.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/debuggery.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/debuggery.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/debuggery.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/debuggery.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/debuggery.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/debuggery.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/debuggery.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/debuggery.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/debuggery.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/debuggery.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/debuggery.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/debuggery.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/debuggery.wordpress.com/68/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debuggery.net&amp;blog=26135019&amp;post=68&amp;subd=debuggery&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://debuggery.net/2010/09/27/whats-up-with-getters-and-setters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://debuggery.files.wordpress.com/2010/09/gettersandsetters.jpg?w=150" />
		<media:content url="http://debuggery.files.wordpress.com/2010/09/gettersandsetters.jpg?w=150" medium="image">
			<media:title type="html">What&#039;s up with Getters and Setters?</media:title>
		</media:content>

		<media:content url="http://0.gravatar.com/avatar/2431d4e34d804e1a1f57166d14462dd8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bpjohnson</media:title>
		</media:content>
	</item>
		<item>
		<title>Exceptions and the handling thereof&#8230;</title>
		<link>http://debuggery.net/2010/09/16/exceptions-and-the-handling-thereof/</link>
		<comments>http://debuggery.net/2010/09/16/exceptions-and-the-handling-thereof/#comments</comments>
		<pubDate>Thu, 16 Sep 2010 18:50:02 +0000</pubDate>
		<dc:creator>Bryan</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://debuggery.net/?p=60</guid>
		<description><![CDATA[Ralph Schindler has an article up about the new Exception features of PHP 5.3, as well as some best practices involving Exceptions. To be honest, I hadn&#8217;t realized that new Exception types had been added to the SPL, and when I first read it in Ralph&#8217;s article, I thought: &#8220;Big whup, extending the good ol&#8217; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debuggery.net&amp;blog=26135019&amp;post=60&amp;subd=debuggery&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="attachment_64" class="wp-caption aligncenter" style="width: 610px"><a href="http://debuggery.files.wordpress.com/2010/09/exception1.jpg"><img class="size-full wp-image-64" title="Exceptions and the Handling Thereof..." src="http://debuggery.files.wordpress.com/2010/09/exception1.jpg?w=600&#038;h=297" alt="" width="600" height="297" /></a><p class="wp-caption-text">Exceptions and the Handling Thereof...</p></div>
<p><a href="http://ralphschindler.com/" target="_blank">Ralph Schindler</a> has an <a href="http://ralphschindler.com/2010/09/15/exception-best-practices-in-php-5-3" target="_blank">article up about the new Exception features</a> of PHP 5.3, as well as some best practices involving Exceptions. To be honest, I hadn&#8217;t realized that new Exception types had been added to the SPL, and when I first read it in Ralph&#8217;s article, I thought: &#8220;Big whup, extending the good ol&#8217; Exception class is good enough for me.&#8221;</p>
<p>But I kept reading and now I&#8217;m really excited. See, it&#8217;s not just that there are new standard exception types, but there&#8217;s now a consensus way to incorporate exceptions into your library code. <a href="http://framework.zend.com/wiki/display/ZFDEV2/Proposal+for+Exceptions+in+ZF2?showComments=false" target="_blank">Zend</a> and <a href="http://wiki.php.net/pear/rfc/pear2_exception_policy" target="_blank">Pear</a> seem to be agreeing, and while normally I&#8217;m not a fan of either&#8217;s code standards, this one I like.</p>
<p>In fact, I&#8217;m going to steal Zend&#8217;s standard nearly word for word:</p>
<blockquote>
<ul>
<li>There <strong>WILL NOT</strong> be a top level <tt>anApp\Exception</tt> class</li>
<li>Each package <strong>WILL</strong> define a marker <tt>Exception</tt> interface; subpackages may optionally define a similar marker interface extending that interface.</li>
<li>Each package <strong>WILL</strong> define a generic <tt>&lt;package&gt;Exception</tt> class (eg. <tt>anApp\SmartObject\Exception</tt>), extending <tt>\Exception</tt> and implementing the component level <tt>Exception</tt> marker interface.</li>
<li>Exceptions extending other SPL exception classes and implementing the marker <tt>Exception</tt> interface <strong>MAY</strong>be created.
<ul>
<li>Exceptions deriving from SPL exception classes <strong>SHOULD</strong> be named after the SPL exception they extend, but <strong>MAY</strong> be named uniquely. In most cases, we would recommend using the original SPL exception name to prevent a proliferation of exceptions.</li>
<li>Exceptions not named after SPL exceptions <strong>WILL</strong> be named meaningfully: <tt>InvalidTemplateException</tt>, <tt>UnbalancedTagException</tt>, etc. Exception types can be re-used, but only if the name has a similar meaning in each context in which it is used.</li>
</ul>
</li>
<li>Because the previous requirement may lead to a proliferation of exception classes, exception classes <strong>MAY</strong> be grouped into an &#8220;Exception&#8221; subcomponent. The rule of thumb will be that if the number of exception classes exceeds 1/2 the number of regular classes and interfaces, they should be segregated.</li>
</ul>
</blockquote>
<p>This is exciting because it gives you tons of options for throwing and catching exceptions, and for providing context for your errors in a way other programmers can easily understand.</p>
<p>Now I just need to nail down the package/subpackage/class naming conventions. Woot!</p>
<br />Filed under: <a href='http://debuggery.net/category/code/'>Code</a>, <a href='http://debuggery.net/category/code/php/'>PHP</a> Tagged: <a href='http://debuggery.net/tag/php5/'>php</a>, <a href='http://debuggery.net/tag/programming/'>Programming</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/debuggery.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/debuggery.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/debuggery.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/debuggery.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/debuggery.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/debuggery.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/debuggery.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/debuggery.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/debuggery.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/debuggery.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/debuggery.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/debuggery.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/debuggery.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/debuggery.wordpress.com/60/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debuggery.net&amp;blog=26135019&amp;post=60&amp;subd=debuggery&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://debuggery.net/2010/09/16/exceptions-and-the-handling-thereof/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="" />
		<media:content url="" medium="image" />

		<media:content url="http://0.gravatar.com/avatar/2431d4e34d804e1a1f57166d14462dd8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bpjohnson</media:title>
		</media:content>

		<media:content url="http://debuggery.files.wordpress.com/2010/09/exception1.jpg" medium="image">
			<media:title type="html">Exceptions and the Handling Thereof...</media:title>
		</media:content>
	</item>
		<item>
		<title>Smart Objects sneak preview</title>
		<link>http://debuggery.net/2010/09/15/smart-objects-sneak-preview/</link>
		<comments>http://debuggery.net/2010/09/15/smart-objects-sneak-preview/#comments</comments>
		<pubDate>Wed, 15 Sep 2010 12:53:22 +0000</pubDate>
		<dc:creator>Bryan</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://debuggery.net/?p=49</guid>
		<description><![CDATA[Here&#8217;s a bit of a sneak preview. I&#8217;ll let the code speak for itself: [codesyntax lang="php"] &#60;?php include_once(realpath(dirname(__FILE__).'/lib/smartObjects/lib.inc')); \SmartObject\Connect(array( 'driver' =&#62; 'mysql', 'host' =&#62; '127.0.0.1', 'database' =&#62; 'testdb', 'user' =&#62; 'dbuser', // not my real db user 'password' =&#62; 'dbpass' // not my real db password )); \SmartObject\Register('User'); //Register "User" and get "Users" factory for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debuggery.net&amp;blog=26135019&amp;post=49&amp;subd=debuggery&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a bit of a sneak preview. I&#8217;ll let the code speak for itself:</p>
<p>[codesyntax lang="php"]</p>
<pre>&lt;?php
include_once(realpath(dirname(__FILE__).'/lib/smartObjects/lib.inc'));

\SmartObject\Connect(array(
                         'driver' =&gt; 'mysql',
                         'host' =&gt; '127.0.0.1',
                         'database' =&gt; 'testdb',
                         'user' =&gt; 'dbuser',
                         // not my real db user
                         'password' =&gt; 'dbpass'
                         // not my real db password
                     ));

\SmartObject\Register('User'); //Register "User" and get "Users" factory for free!

  $users = new Users();

  $users-&gt;sn('Johnson')
    -&gt;or()
    -&gt;sn('Clark')
    -&gt;orderBy('sn DESC'); // No query is performed until we try to use the Users object to get at query data.

foreach ($users as $user) {
   echo "Setting access to 0 for: ".$user-&gt;gn." ".$user-&gt;sn."\n";
   $user-&gt;access = 0;
   $user-&gt;update();
}

echo "Setting access back to 1 for all users in our query.\n";
$users-&gt;beginTransaction();
$users-&gt;each()-&gt;access = 1;
$users-&gt;each()-&gt;update();
$users-&gt;endTransaction();

print "&lt;ul&gt;\n";
$users-&gt;each(
	  function($user) {
	     print "&lt;li&gt;".$user-&gt;fullName."&lt;/li&gt;";
	  }
	);
print "&lt;/ul&gt;\n";
?&gt;</pre>
<p>[/codesyntax]</p>
<br />Filed under: <a href='http://debuggery.net/category/code/'>Code</a>, <a href='http://debuggery.net/category/code/php/'>PHP</a> Tagged: <a href='http://debuggery.net/tag/php5/'>php</a>, <a href='http://debuggery.net/tag/programming/'>Programming</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/debuggery.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/debuggery.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/debuggery.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/debuggery.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/debuggery.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/debuggery.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/debuggery.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/debuggery.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/debuggery.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/debuggery.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/debuggery.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/debuggery.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/debuggery.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/debuggery.wordpress.com/49/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debuggery.net&amp;blog=26135019&amp;post=49&amp;subd=debuggery&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://debuggery.net/2010/09/15/smart-objects-sneak-preview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="" />
		<media:content url="" medium="image" />

		<media:content url="http://0.gravatar.com/avatar/2431d4e34d804e1a1f57166d14462dd8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bpjohnson</media:title>
		</media:content>
	</item>
		<item>
		<title>One Step Forward&#8230;</title>
		<link>http://debuggery.net/2010/09/14/one-step-forward/</link>
		<comments>http://debuggery.net/2010/09/14/one-step-forward/#comments</comments>
		<pubDate>Tue, 14 Sep 2010 18:48:26 +0000</pubDate>
		<dc:creator>Bryan</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://debuggery.net/?p=44</guid>
		<description><![CDATA[Not quite two steps back. I&#8217;ve been plugging away at Smart Objects, as a way to get a feel for the rest of anApp5, especially the base anObject, the object that carries the functionality common to all anApp objects. See, I&#8217;m balls at TDD. In a perfect world, I&#8217;d spec out anObject and Smart Objects, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debuggery.net&amp;blog=26135019&amp;post=44&amp;subd=debuggery&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://debuggery.files.wordpress.com/2010/09/onestepforward1.jpg"><img class="size-full wp-image-45 alignleft" title="One Step Forward" src="http://debuggery.files.wordpress.com/2010/09/onestepforward1.jpg?w=297&#038;h=198" alt="" width="297" height="198" /></a>Not quite two steps back. I&#8217;ve been plugging away at <a href="http://github.com/bpjohnson/anApp5/wiki/smartObjects" target="_blank">Smart Objects</a>, as a way to get a feel for the rest of anApp5, especially the base anObject, the object that carries the functionality common to <em>all</em> <a href="http://github.com/bpjohnson/anApp5" target="_blank">anApp</a> objects. See, I&#8217;m balls at TDD. In a perfect world, I&#8217;d spec out anObject and Smart Objects, write tests for them, then write the code (or somesuch methodology). Unfortunately I&#8217;m awful at that kind of coding. Undisciplined is one word. So I write some on anObject, then some on Smart Objects, then tweak out anObject when I hit a wall with Smart Objects&#8230; Back and forth, back and forth.</p>
<p>Testing? What&#8217;s that? Sounds like it&#8217;d be a good idea. Someone should get on that.</p>
<p>This week&#8217;s problem came down to scope: there&#8217;s currently no way to call a closure and give it $this scope. My thinking was something along the lines of:</p>
<p>[codesyntax lang="php" tab_width="2"]</p>
<pre>class foo {

	public $closures = array(
		'bar' =&gt; function($args) {
		echo "Class: ".get_class($this)."\n";
		echo "Method Bar called with:\n";
		var_dump($args);
		}
	);

	public function __call($methodName, $args) {
		if (in_array($methodName, $this-&gt;closures)) {
		  $this-&gt;closures[$methodName]($args); //or
		  // call_user_func_array(array($this, "closures['$methodName']"), $args);
		}
	}
}</pre>
<p>[/codesyntax]</p>
<p>Crazy talk, I know. But this would let me do lisp-style advice and such. But no love.</p>
<p>So I have to come up with a hacky solution. I&#8217;m leaning now towards having advisable functions follow the convention of being private and starting with an underscore, but being called without:</p>
<p>[codesyntax lang="php" tab_width="2"]</p>
<pre>class foo extends anObject {
	private function __bar() {
		echo "Called __bar\n";
	}
}

$foo = new foo();
$foo-&gt;bar();</pre>
<p>[/codesyntax]</p>
<p>Then you can do something like:</p>
<p>[codesyntax lang="php"]</p>
<pre>foo::adviseBefore('bar', function() {
	echo "Bar about to be called!\n";
});$foo = new foo();
$foo-&gt;bar(); // Echoes "Bar about to be called!\nCalled __bar\n</pre>
<p>[/codesyntax]</p>
<br />Filed under: <a href='http://debuggery.net/category/code/'>Code</a>, <a href='http://debuggery.net/category/code/php/'>PHP</a> Tagged: <a href='http://debuggery.net/tag/php5/'>php</a>, <a href='http://debuggery.net/tag/programming/'>Programming</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/debuggery.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/debuggery.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/debuggery.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/debuggery.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/debuggery.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/debuggery.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/debuggery.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/debuggery.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/debuggery.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/debuggery.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/debuggery.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/debuggery.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/debuggery.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/debuggery.wordpress.com/44/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debuggery.net&amp;blog=26135019&amp;post=44&amp;subd=debuggery&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://debuggery.net/2010/09/14/one-step-forward/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="" />
		<media:content url="" medium="image" />

		<media:content url="http://0.gravatar.com/avatar/2431d4e34d804e1a1f57166d14462dd8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bpjohnson</media:title>
		</media:content>

		<media:content url="http://debuggery.files.wordpress.com/2010/09/onestepforward1.jpg" medium="image">
			<media:title type="html">One Step Forward</media:title>
		</media:content>
	</item>
		<item>
		<title>From Smashing: Showcase of Interesting Navigation Designs</title>
		<link>http://debuggery.net/2010/09/07/from-smashing-showcase-of-interesting-navigation-designs/</link>
		<comments>http://debuggery.net/2010/09/07/from-smashing-showcase-of-interesting-navigation-designs/#comments</comments>
		<pubDate>Tue, 07 Sep 2010 16:10:51 +0000</pubDate>
		<dc:creator>Bryan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://debuggery.net/?p=31</guid>
		<description><![CDATA[Showcase of Interesting Navigation Designs Smashing Magazine has a good article today about interesting navigation designs. They showcase several sites and offer pretty good criticism, highlighting the pros and cons of the various sites&#8217; unique navigation. My favorites were: Made in Haus — the dual sliding effects, even if I had trouble finding the navigation [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debuggery.net&amp;blog=26135019&amp;post=31&amp;subd=debuggery&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:center;"><a href="http://www.smashingmagazine.com/2010/09/07/showcase-of-interesting-navigation-designs/"><img class="size-full wp-image-32 aligncenter" title="Smashing Magazine: Showcase of Interesting Navigation" src="http://debuggery.files.wordpress.com/2010/09/smashing1.png?w=500&#038;h=278" alt="" width="500" height="278" /></a></p>
<div class="mceTemp">
<dl class="wp-caption alignleft">
<dd class="wp-caption-dd">Showcase of Interesting Navigation Designs</dd>
</dl>
</div>
<p><a href="http://www.smashingmagazine.com/" target="_blank">Smashing Magazine</a> has <a href="http://www.smashingmagazine.com/2010/09/07/showcase-of-interesting-navigation-designs/" target="_blank">a good article today</a> about interesting navigation designs. They showcase several sites and offer pretty good criticism, highlighting the pros and cons of the various sites&#8217; unique navigation. My favorites were:</p>
<ul>
<li> <a href="http://www.madeinhaus.com/" target="_blank">Made in Haus</a> — the dual sliding effects, even if I had trouble finding the navigation arrow</li>
<li><a href="http://komra.de/">Komrade</a> — once I saw that the first link was below the fold, meaning that my screen was smaller than they had designed for</li>
<li><a href="http://www.plinestudios.com/">Pline</a> — for their minimalistic yet sexah vertical nav</li>
<li><a href="http://retinart.net/" target="_blank">Retinart</a> — because I&#8217;m a sucker for the nummy nummy typography</li>
</ul>
<p>I really wanted to like both <a href="http://flywheeldesign.com/" target="_blank">Flywheel Design</a> and <a href="http://www.madebywater.com/" target="_blank">Made By Water</a> but they made me have to think, and I hate doing that when I shouldn&#8217;t have to.</p>
<br />Filed under: <a href='http://debuggery.net/category/uncategorized/'>Uncategorized</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/debuggery.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/debuggery.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/debuggery.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/debuggery.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/debuggery.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/debuggery.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/debuggery.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/debuggery.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/debuggery.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/debuggery.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/debuggery.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/debuggery.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/debuggery.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/debuggery.wordpress.com/31/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debuggery.net&amp;blog=26135019&amp;post=31&amp;subd=debuggery&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://debuggery.net/2010/09/07/from-smashing-showcase-of-interesting-navigation-designs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="" />
		<media:content url="" medium="image" />

		<media:content url="http://0.gravatar.com/avatar/2431d4e34d804e1a1f57166d14462dd8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bpjohnson</media:title>
		</media:content>

		<media:content url="http://debuggery.files.wordpress.com/2010/09/smashing1.png" medium="image">
			<media:title type="html">Smashing Magazine: Showcase of Interesting Navigation</media:title>
		</media:content>
	</item>
		<item>
		<title>Back in the saddle, again&#8230;</title>
		<link>http://debuggery.net/2010/09/02/back-in-the-saddle-again/</link>
		<comments>http://debuggery.net/2010/09/02/back-in-the-saddle-again/#comments</comments>
		<pubDate>Thu, 02 Sep 2010 18:24:15 +0000</pubDate>
		<dc:creator>Bryan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://debuggery.net/?p=11</guid>
		<description><![CDATA[Welcome to Debuggery! It&#8217;s been a while since I&#8217;ve kept a blog, so please bear with me. My name is Bryan Johnson. I&#8217;ve been writing code professionally for about fifteen years now, and have been partner in a software development company for more than five. But I have no formal training, having studied Elizabethan-era English [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debuggery.net&amp;blog=26135019&amp;post=11&amp;subd=debuggery&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Welcome to Debuggery!</p>
<p>It&#8217;s been a while since I&#8217;ve kept a blog, so please bear with me.</p>
<p>My name is Bryan Johnson. I&#8217;ve been writing code professionally for about fifteen years now, and have been partner in <a href="http://12ftguru.com" target="_blank">a software development company</a> for more than five. But I have no formal training, having studied Elizabethan-era English Literature in college. This background, along with a fair amount of skepticism when it comes to &#8220;the right way&#8221; of doing things, gives me a somewhat different view when it comes to writing code. That perspective is what I&#8217;ll be sharing here.</p>
<p>I expect I&#8217;ll also blather on a bit about <a href="http://github.com/bpjohnson">my pet projects</a>, and pretty much anything else that comes to mind.</p>
<p>I hope you stick around.</p>
<br />Filed under: <a href='http://debuggery.net/category/uncategorized/'>Uncategorized</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/debuggery.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/debuggery.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/debuggery.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/debuggery.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/debuggery.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/debuggery.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/debuggery.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/debuggery.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/debuggery.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/debuggery.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/debuggery.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/debuggery.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/debuggery.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/debuggery.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debuggery.net&amp;blog=26135019&amp;post=11&amp;subd=debuggery&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://debuggery.net/2010/09/02/back-in-the-saddle-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="" />
		<media:content url="" medium="image" />

		<media:content url="http://0.gravatar.com/avatar/2431d4e34d804e1a1f57166d14462dd8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bpjohnson</media:title>
		</media:content>
	</item>
	</channel>
</rss>
