<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>Code Naked - PHP</title>
    <link>http://codenaked.org/</link>
    <description>When the going gets tough, the tough get naked.</description>
    <dc:language>en</dc:language>
    <generator>Serendipity 1.5.2 - http://www.s9y.org/</generator>
    <pubDate>Tue, 09 Feb 2010 15:40:26 GMT</pubDate>

    <image>
        <url>http://codenaked.org/templates/default/img/s9y_banner_small.png</url>
        <title>RSS: Code Naked - PHP - When the going gets tough, the tough get naked.</title>
        <link>http://codenaked.org/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>PHP: Irrelevant Again</title>
    <link>http://codenaked.org/archives/41-PHP-Irrelevant-Again.html</link>
            <category>PHP</category>
            <category>Software Development</category>
    
    <comments>http://codenaked.org/archives/41-PHP-Irrelevant-Again.html#comments</comments>
    <wfw:comment>http://codenaked.org/wfwcomment.php?cid=41</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://codenaked.org/rss.php?version=2.0&amp;type=comments&amp;cid=41</wfw:commentRss>
    

    <author>nospam@example.com (Matthew Purdon)</author>
    <content:encoded>
    So I was pointed to the &lt;a href=&quot;http://csclub.uwaterloo.ca/contest/profile.php?user_id=1408&quot; title=&quot;My Google AI Profile&quot;&gt;Google AI Challenge&lt;/a&gt; being put on by the &lt;a href=&quot;http://csclub.ca/&quot; title=&quot;Matthew Purdon&#039;s profile on Google AI Challenge&quot;&gt;University of Waterloo Computer Science Club&lt;/a&gt; by a &lt;a href=&quot;http://newfoo.net/&quot; title=&quot;Jim Connell&#039;s blog&quot;&gt;friend of mine&lt;/a&gt;. It&#039;s so funny to see the paradox of PHP so starkly portrayed. Take a look at the &lt;a href=&quot;http://csclub.uwaterloo.ca/contest/starter_packages.php&quot; title=&quot;Google AI Start packages page&quot;&gt;starter packages&lt;/a&gt; that are provided for the challenge, you will notice a couple of things:&lt;br /&gt;
&lt;br /&gt;
1) &lt;strong&gt;PHP is not to be found&lt;/strong&gt; on there at all, even though its chief rivals Ruby and Python are. In fact, Python was one of the first ones available.&lt;br /&gt;
2) &lt;strong&gt;The page itself is written using PHP&lt;/strong&gt; to drive the content, presumably by some one-off page action rather than a framework implementation (the HTML is too packed hehe)&lt;br /&gt;
&lt;br /&gt;
This sums up the general feeling the world has towards PHP: it&#039;s fine for throwing together a quick web page, but who would use it to actually do any programming with? I am not complaining mind you; even though I have been in the PHP game a long time, I love &lt;a href=&quot;http://python.org&quot; title=&quot;Python home page&quot;&gt;Python&lt;/a&gt; and wish I could get more work doing it! 
    </content:encoded>

    <pubDate>Tue, 09 Feb 2010 07:24:28 -0800</pubDate>
    <guid isPermaLink="false">http://codenaked.org/archives/41-guid.html</guid>
    
</item>
<item>
    <title>Apparently I suck</title>
    <link>http://codenaked.org/archives/40-Apparently-I-suck.html</link>
            <category>Being a Contractor</category>
            <category>PHP</category>
    
    <comments>http://codenaked.org/archives/40-Apparently-I-suck.html#comments</comments>
    <wfw:comment>http://codenaked.org/wfwcomment.php?cid=40</wfw:comment>

    <slash:comments>1</slash:comments>
    <wfw:commentRss>http://codenaked.org/rss.php?version=2.0&amp;type=comments&amp;cid=40</wfw:commentRss>
    

    <author>nospam@example.com (Matthew Purdon)</author>
    <content:encoded>
    I was &lt;a href=&quot;http://outspokenmedia.com/online-marketing/you-just-suck/&quot; title=&quot;Outspoken Media Article&quot;&gt;reading an article&lt;/a&gt; today on &lt;a href=&quot;http://outspokenmedia.com&quot; title=&quot;outspoken media home page&quot;&gt;outspokenmedia.com&lt;/a&gt; that was written back in April of 2009 and &lt;strong&gt;I was pretty impressed with it&lt;/strong&gt;. I too feel that not only are people using the recession as an excuse for not trying, but also that employers are using it as an excuse to get rid of employees without having anyone put up a fight. &quot;I&#039;m sorry Bob, in this economy we have all had to make cutbacks, as a result we are going to give you 10 minutes to get your stuff together and say goodbye to the job you have had for 5 years.&quot; To which Bob replies &quot;I can totally understand, at least you are going to give me my Christmas Bonus before I leave right?&quot; hahaha. Poor little developer, you&#039;d be cute if we weren&#039;t embarrassed to look you in the eye.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://lisabarone.com/&quot; title=&quot;Lisa Barone&#039;s Home page&quot;&gt;Lisa Barone&lt;/a&gt; goes through a few points that employees and especially contractors should be doing in order to not only stay afloat, but to excel during these crazy times. &lt;strong&gt;I feel that I am performing the majority of items that Lisa suggests we do&lt;/strong&gt;: Learn something new, Work harder than everyone else, Do the leg work, Take risks, and Shut up. I am always learning and I love it so this is not a problem for me. Even now that I am not on a full-time gig I still sit in front of my computer for a minimum of 8 hours a day. Not 8 hours a day watching YouTube, but spent coding. I have written &lt;a href=&quot;http://github.com/mpurdon/Naked&quot; title=&quot;Naked Framework on Git Hub&quot;&gt;a framework&lt;/a&gt; from the ground up using PHP5.3 features such as namespaces, closures/lambdas, __callStatic, and late static binding. I use these features to build next level framework components such as Dependency Injection, Annotations and a Unit of Work maintained ORM layer. A little over 7,000 lines of code in a couple of weeks. I have also tried out what the development work cycle is like with &lt;a href=&quot;http://www.zend.com/en/products/studio/&quot; title=&quot;Zend Studio Home Page&quot;&gt;Zend Studio 7.1&lt;/a&gt; and &lt;a href=&quot;http://www.zend.com/en/products/server/&quot; title=&quot;Zend Server Home Page&quot;&gt;Zend Server CE&lt;/a&gt;. I also used those tools to build a brand new &lt;a href=&quot;http://framework.zend.com/&quot; title=&quot;Zend Framework Home Page&quot;&gt;Zend Framework&lt;/a&gt; application using a modular layout and integrating &lt;a href=&quot;http://www.doctrine-project.org/&quot; title=&quot;The Doctrine ORM Project Home Page&quot;&gt;Doctrine&lt;/a&gt; as the ORM layer. Finally I have started to work with &lt;a href=&quot;http://code.google.com/webtoolkit/&quot; title=&quot;GWT Home Page&quot;&gt;GWT&lt;/a&gt; and have discovered that it can actually be really fun to work with. There are a few other items that I have been researching and playing with, but long story short, &lt;strong&gt;I have used my free time to the max increasing my skill set&lt;/strong&gt;.&lt;br /&gt;
&lt;br /&gt;
The one thing that I am still sucking at is surrounding myself with fighters. &lt;strong&gt;It&#039;s hard to surround yourself with anyone when you work from home&lt;/strong&gt;. I feel that I need to start being more involved in the PHP community and so I have been trying to find a PHP user group in Toronto that I could attend and perhaps speak at. So far, no luck. If any of you know of a group in the GTA please feel free to tell me about it in the comments! 
    </content:encoded>

    <pubDate>Thu, 28 Jan 2010 09:15:54 -0800</pubDate>
    <guid isPermaLink="false">http://codenaked.org/archives/40-guid.html</guid>
    
</item>
<item>
    <title>Interfaces: You are doing them wrong.</title>
    <link>http://codenaked.org/archives/39-Interfaces-You-are-doing-them-wrong..html</link>
            <category>PHP</category>
    
    <comments>http://codenaked.org/archives/39-Interfaces-You-are-doing-them-wrong..html#comments</comments>
    <wfw:comment>http://codenaked.org/wfwcomment.php?cid=39</wfw:comment>

    <slash:comments>1</slash:comments>
    <wfw:commentRss>http://codenaked.org/rss.php?version=2.0&amp;type=comments&amp;cid=39</wfw:commentRss>
    

    <author>nospam@example.com (Matthew Purdon)</author>
    <content:encoded>
    Normally I don&#039;t do any sort of Introduction to Object Oriented Programming posts because to be honest, it&#039;s been a long time since I read chapter one and&lt;strong&gt; thinking in objects comes naturally to me&lt;/strong&gt;. Today I happened across the &lt;a href=&quot;http://php.net/manual/en/language.oop5.interfaces.php&quot; title=&quot;Interfaces manual entry&quot;&gt;Interfaces section&lt;/a&gt; of the PHP manual; the examples and comments on that page were so brutal I thought maybe I should do a public service and write something about how to create a clear object model using a couple of rules of thumb.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;In my opinion, one of the most misunderstood OOP mechanisms in the PHP world is the Interface&lt;/strong&gt;. Unfortunately, the manual seems to support my opinion. In the first example we have the class Template implementing the interface iTemplate. What is an iTemplate? The rest of the examples are even worse: class a implements b. No wonder developers struggle with interfaces when the people that literally wrote the book for them don&#039;t seem to get it. Even worse are the comments though, class Rain extends Weather and implements Water? What? Maybe if they mean water as in the sense of watering your lawn. Even so, there has got to be a better name for it than that. The way that interfaces are done in the &lt;a href=&quot;http://framework.zend.com&quot; title=&quot;Zend Framework Home Page&quot;&gt;Zend Framework&lt;/a&gt; offers a real-world example of bad interface design. Take a look at the following sentence and let&#039;s see if you can make sense of what the involved components are:&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;Zend_Validate_Date is a Zend_Validate_Abstract and can Zend_Validate_Interface&lt;/em&gt;&lt;br /&gt;
&lt;br /&gt;
Now to be completely fair, these class names do get ugly as a result of having to bear the weight of pseudo-namespacing, but &lt;strong&gt;if your interface is actually called &quot;Interface&quot; you know you have a problem&lt;/strong&gt;. Let&#039;s look at it again but this time we will be using &lt;a href=&quot;http://www.php.net/manual/en/migration53.new-features.php&quot; title=&quot;New features in PHP 5.3 list&quot;&gt;PHP 5.3&lt;/a&gt;+ (which you should be using because it&#039;s awesome) and Zend Framework 2.0 - which may have namespace support:&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;Date is an Abstract and can Interface&lt;/em&gt;&lt;br /&gt;
&lt;br /&gt;
This does not describe what type of an object the Date is. Is it a calendar date? Is it a fruit that can be dried and old people drink to help them go #2 more regularly? Or maybe it is a meeting involving two or more people in order to determine if their physical proximity elicits a chemical response. Who knows? And don&#039;t even get me started on &quot;can Interface&quot;! Maybe that&#039;s what happens if there is chemistry between the people on the Date? Now if you are an experienced OOP developer, you will know that Abstract is the home of some common functionality that all child classes share and that the Interface defines the contract that any objects implementing it must fulfill. But it doesn&#039;t tell you anything about what type of functionality is common to the children of the abstract or what types of behavior must be implemented by objects implementing the interface.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Designing objects can be fairly easy for the most part if you take the stance that your objects are &lt;a href=&quot;http://en.wikipedia.org/wiki/Noun&quot; title=&quot;Wikipedia entry for Noun&quot;&gt;nouns&lt;/a&gt; and your interfaces are &lt;a href=&quot;http://en.wikipedia.org/wiki/Adjective&quot; title=&quot;Wikipedia entry for Adjective&quot;&gt;adjectives&lt;/a&gt;&lt;/strong&gt;. Until you get better at it, try to add the &lt;a href=&quot;http://en.wikipedia.org/wiki/Suffix&quot; title=&quot;Wikipedia entry for Suffix&quot;&gt;suffix&lt;/a&gt; &quot;able&quot; to indicate that objects implementing it are capable of doing something. Try this version of the Zend Framework validation action:&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;Date is a Validator and is Validatable&lt;/em&gt;&lt;br /&gt;
&lt;br /&gt;
You won&#039;t always be able to use the &quot;able&quot; rule of thumb, but going through the process of trying to think of one will help you arrive at a better object model. Take a look at a few more examples:&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;A Circle is a Shape and is Drawable&lt;br /&gt;
A TeddyBear is a Toy and is Huggable&lt;br /&gt;
A CardDeck is an ArrayObject and is both Countable and Sortable&lt;/em&gt;&lt;br /&gt;
&lt;br /&gt;
So hopefully these examples help give you an idea how easy it is to create good code. &lt;strong&gt;As always when it comes to designing objects, your best tool is simply reading the objects out loud&lt;/strong&gt;. The better your design, the less like Yoda you will sound. Of course I couldn&#039;t leave this post without throwing down some code, and since I was most appalled by the Weather examples in the manual comments I thought I would do my own weather example. The real key here is to note that not only do weather conditions such as the amount of clouds and the UV index rating affect what the actual temperature feels like, so can what you wear. In other words, weather can use objects of completely different types to do work because it knows that those objects are capable of doing a particular thing. &lt;br /&gt;&lt;a href=&quot;http://codenaked.org/archives/39-Interfaces-You-are-doing-them-wrong..html#extended&quot;&gt;Continue reading &quot;Interfaces: You are doing them wrong.&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Sat, 16 Jan 2010 05:35:18 -0800</pubDate>
    <guid isPermaLink="false">http://codenaked.org/archives/39-guid.html</guid>
    
</item>
<item>
    <title>I thought Zend_Soap was going to be easy</title>
    <link>http://codenaked.org/archives/38-I-thought-Zend_Soap-was-going-to-be-easy.html</link>
            <category>PHP</category>
    
    <comments>http://codenaked.org/archives/38-I-thought-Zend_Soap-was-going-to-be-easy.html#comments</comments>
    <wfw:comment>http://codenaked.org/wfwcomment.php?cid=38</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://codenaked.org/rss.php?version=2.0&amp;type=comments&amp;cid=38</wfw:commentRss>
    

    <author>nospam@example.com (Matthew Purdon)</author>
    <content:encoded>
    But then I tried to use it. I had a project that I needed to respond to &lt;a href=&quot;http://en.wikipedia.org/wiki/SOAP&quot; title=&quot;Wikipedia SOAP entry&quot;&gt;SOAP&lt;/a&gt; requests and considering the issues I had &lt;a href=&quot;http://codenaked.org/archives/29-SOAP-Kills.html&quot; title=&quot;SOAP Kills blog post&quot;&gt;last time&lt;/a&gt; I played with SOAP, I thought I&#039;d try it a different way this time. The Zend framework is always described as being a collection of components that you can wire together in order to get work done. Most of the time, you use it to build a full MVC stack application, but I only needed one component (I thought) in order to get my work done.&lt;br /&gt;
&lt;br /&gt;
Turns out you need a whole bunch of junk in order to be able to use the Zend_Soap component without a full copy of the Zend Framework:&lt;br /&gt;
&lt;br /&gt;
Zend_Exception - I always thought this was a dumb thing in the first place. I use the SPL exceptions for my stuff.&lt;br /&gt;
Zend_Loader - What? Why? I required my class and most of the ZF uses requires as well so I am not sure why it wanted the loader&lt;br /&gt;
Zend_Registry - I thought maybe to cache the wsdl? But that&#039;s cached in /tmp by the underlying PHP soap action&lt;br /&gt;
Zend_Uri - Makes sense, the service is a web service after all&lt;br /&gt;
Zend_Validate - Have to make sure the Uri is valid I guess&lt;br /&gt;
Zend_Soap - duh&lt;br /&gt;
&lt;br /&gt;
In the end, I needed 106 source files in 20 folders to get things done. This is especially crazy when you think that you can get a boiler plate client working by doing this:&lt;textarea name=&quot;code&quot; class=&quot;PHP&quot;&gt;
$client = new SoapClient(&#039;some.wsdl&#039;);
$response = $client-&gt;getSomething(&#039;foo&#039;);&lt;/textarea&gt;So you may be asking yourself if the Zend_Soap really needs all of those files. I thought so as well, but to be honest, I am trying to use the component to get a quick start on the service, not to spend an annoyingly long time going through each component only pulling out the exact source files I needed and placing them in their proper place in my library folder. You may also be asking yourself why I would bother in the first place. I&#039;ll tell you why, dear reader, it&#039;s because I wanted automatic WSDL generation! And it&#039;s because of this small desire that my troubles began. &lt;br /&gt;&lt;a href=&quot;http://codenaked.org/archives/38-I-thought-Zend_Soap-was-going-to-be-easy.html#extended&quot;&gt;Continue reading &quot;I thought Zend_Soap was going to be easy&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Wed, 13 Jan 2010 15:56:20 -0800</pubDate>
    <guid isPermaLink="false">http://codenaked.org/archives/38-guid.html</guid>
    
</item>
<item>
    <title>Naked PHP Framework on Git Hub</title>
    <link>http://codenaked.org/archives/37-Naked-PHP-Framework-on-Git-Hub.html</link>
            <category>PHP</category>
    
    <comments>http://codenaked.org/archives/37-Naked-PHP-Framework-on-Git-Hub.html#comments</comments>
    <wfw:comment>http://codenaked.org/wfwcomment.php?cid=37</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://codenaked.org/rss.php?version=2.0&amp;type=comments&amp;cid=37</wfw:commentRss>
    

    <author>nospam@example.com (Matthew Purdon)</author>
    <content:encoded>
    So I have been using &lt;a href=&quot;http://git-scm.com&quot; title=&quot;Git home page&quot;&gt;git&lt;/a&gt; for a while now, and I really like it. &lt;strong&gt;I really appreciate being able to check in code without having to have a server available&lt;/strong&gt; and for some reason it just feels a lot more solid than &lt;a href=&quot;http://subversion.tigris.org/&quot; title=&quot;Subversion home page&quot;&gt;Subversion&lt;/a&gt;. Case in point, today I was merging a big branch back into trunk and it was throwing a ton of conflicts on tabbed versus spaced lines... Easy enough to fix but still annoying in the first place. I don&#039;t seem to get those kinds of issues with git. *shrug*&lt;br /&gt;
&lt;br /&gt;
So I am just doing a quick post to say that I have put my toy framework up on &lt;a href=&quot;http://github.com/mpurdon/Naked&quot; title=&quot;Naked Framwork page on GitHub&quot;&gt;GitHub&lt;/a&gt; so that I can keep track of it, share it with some other people and because I want to be like all of the other cool kids and have some open source junk on GitHub. I feel cooler already!&lt;br /&gt;
&lt;br /&gt;
The framework itself has some interesting features, but as I said, it&#039;s mostly just there to experiment on. Check out what&#039;s working now:&lt;br /&gt;
&lt;br /&gt;
* MVC stack - Duh, isn&#039;t every framework now?&lt;br /&gt;
* Highly modular - Everything for a module lives in the module. Configuration, Routes, etc can all be dropped in place as one folder.&lt;br /&gt;
* Uses namespaces - The initial reason I started writing this framework was to get namespace experience. Love them.&lt;br /&gt;
* Annotations - Allows you to specify stuff in a method/property doc block. @Inject for example.&lt;br /&gt;
* &lt;a href=&quot;http://codenaked.org/archives/36-Dependency-Injection-Me-likey.html&quot; title=&quot;My DI implementation&quot;&gt;Dependency Injection&lt;/a&gt; - Uses type hinting and annotations to inject using constructor and/or setter injection. Can use lambdas/closures as object factories. It&#039;s sick, trust me.&lt;br /&gt;
* ORM - Has a very &lt;a href=&quot;http://djangoproject.com/&quot; title=&quot;The Django Framework home page&quot;&gt;Django-like&lt;/a&gt; object manager. Want to get all BMWs with a model of 750i newer than 2007? It&#039;s easy: $cars = Bmw::objects()-&gt;filter(&#039;model_eq=750i&#039;)-&gt;filter(&#039;year_gt=2007&#039;); Working on implementing single table inheritance right now where all classes for a hierarchy map onto on database table. Uses lots of late static binding.&lt;br /&gt;
* Unit of Work - Basically handles persisting Domain Models transparently using the ORM. If you load an object, change it and then delete it. Only the delete is persisted and the changes are ignored.  You can read more about it on &lt;a href=&quot;http://martinfowler.com/eaaCatalog/unitOfWork.html&quot; title=&quot;Unit of Work on Martin Fowler&#039;s website&quot;&gt;Martin Fowler&#039;s site&lt;/a&gt;. It&#039;s pretty awesome too.&lt;br /&gt;
* Templating - Another port from django. Basically allows for non-php template syntax. I like it, you might not.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what is on the road map to completion:&lt;br /&gt;
&lt;br /&gt;
* Forms - You guessed it. Django port again. Basically each property in a model is a field with validation and all of that junk built in. The forms handle wrangling them to and from the browser.&lt;br /&gt;
* Signals - Very similar to how plugins work in the Zend Framework. Instead of being rigidly contained however, you can emit any old signal to the signal bus and it can be ignored or handled by various listeners&lt;br /&gt;
* Automatic auditing - The unit of work knows what changes have happened, by adding an @auditable annotation to a class the Unit of Work will track the changes to the object in an auditing table.&lt;br /&gt;
* Automatic Sphynx updating - Again the unit of work knows when an object has been updated so if it has the @searchable annotation it will automatically update the sphynx indexes.&lt;br /&gt;
* Creation tools. The point is that this framework pretty much wires up everything for you so you just get down to business. Need something similar to Zend_Tool to help peeps out. &lt;br /&gt;
* Who knows. After all of that junk is in place... Well, I&#039;ll probably have started all over again ... *sigh* A great way to learn a lot about the new PHP 5.3+ features though!&lt;br /&gt;
 
    </content:encoded>

    <pubDate>Fri, 08 Jan 2010 07:59:24 -0800</pubDate>
    <guid isPermaLink="false">http://codenaked.org/archives/37-guid.html</guid>
    
</item>
<item>
    <title>Dependency Injection: Me likey</title>
    <link>http://codenaked.org/archives/36-Dependency-Injection-Me-likey.html</link>
            <category>PHP</category>
    
    <comments>http://codenaked.org/archives/36-Dependency-Injection-Me-likey.html#comments</comments>
    <wfw:comment>http://codenaked.org/wfwcomment.php?cid=36</wfw:comment>

    <slash:comments>2</slash:comments>
    <wfw:commentRss>http://codenaked.org/rss.php?version=2.0&amp;type=comments&amp;cid=36</wfw:commentRss>
    

    <author>nospam@example.com (Matthew Purdon)</author>
    <content:encoded>
    So I spent some time over the holidays working on my proof of concept framework. One of the key features I added was something I have always been curious about but never really got around to playing with, &lt;a href=&quot;http://en.wikipedia.org/wiki/Dependency_injection&quot; title=&quot;Wikipedia Entry&quot;&gt;Dependency Injection&lt;/a&gt;. I thought the idea seemed to be powerful but I never really &lt;a href=&quot;http://en.wikipedia.org/wiki/Grok&quot; title=&quot;Wikipedia Entry&quot;&gt;grokked&lt;/a&gt; it until I sat down and started to implement my own DI container. The first thing I did was hit google and search for &quot;PHP Dependency Injection&quot;. It turns out there are a lot of frameworks out there now that support some form of injection but I wanted to make sure I was taking the best ideas from all of them and rolling them into my own. I decided to start with Constructor Injection as it is the easiest to implement, but I also wanted to introduce the concept of a context. One of the things we have to contend with frequently in software development is the transition of our code from development environments to production environments, I wanted my framework to knit itself together automatically for whatever environment it was being deployed in. For example, when I am in development I want my logger to use the &lt;a href=&quot;http://firephp.org/&quot; title=&quot;FirePHP Home Page&quot;&gt;FirePHP&lt;/a&gt; extension and have it log at the debug level. In production I want my logger to be completely silent for all but critical errors which are logged to a remote monitoring server. Most of the time I see this implemented in some form of Environment via an init call&lt;textarea name=&quot;code&quot; class=&quot;PHP&quot;&gt;
    /**
     * Initializes the main logger
     *
     */
    protected function _initLogger()
    {
        // logging handler
        $logger = new Zend_Log();

        // general logger, in charge of writing important info to PHP_ERROR
        $stdWriter = new App_Log_Writer_Error();
        $stdWriter-&gt;addFilter(Zend_Log::DEBUG);
        $stdWriter-&gt;addFilter(Zend_Log::INFO);

        // If we are not in production and not running from command line,
        // send logging info to FirePHP
        if (!$this-&gt;isProduction()) {
            // queries
            if ((bool) $this-&gt;getConfig()-&gt;log-&gt;writers-&gt;query-&gt;enabled) {
                $queries = new App_Log_Writer_Query(
                    $this-&gt;getConfig()-&gt;log-&gt;writers-&gt;query-&gt;uri);
                $logger-&gt;addWriter($queries);
                $stdWriter-&gt;addFilter(9);
            }

            // firePHP
            if ((bool) $this-&gt;getConfig()-&gt;log-&gt;writers-&gt;firePHP-&gt;enabled) {
                $firePhp = new Zend_Log_Writer_Firebug();
                $firePhp-&gt;addFilter(new Zend_Log_Filter_Priority(9, &#039;!=&#039;));
                $firePhp-&gt;setPriorityStyle(8, &#039;TABLE&#039;);
                $logger-&gt;addWriter($firePhp);
                $stdWriter-&gt;addFilter(8);
            }

            // debug
            if ((bool) $this-&gt;getConfig()-&gt;log-&gt;writers-&gt;debug-&gt;enabled) {
                $queries = new App_Log_Writer_Debug(
                    $this-&gt;getConfig()-&gt;log-&gt;writers-&gt;debug-&gt;uri);
                $logger-&gt;addWriter($queries);
            }
        }

        $logger-&gt;addWriter($stdWriter);
        Zend_Registry::set(&#039;logger&#039;, $logger);
        $this-&gt;_logger = $logger;
    }&lt;/textarea&gt; As you can see, there are a lot of implementation details that the environment needs to know about in order to get logging together. Even worse is the fact that if you need to get at the logger in code other than in the Environment class itself you need to get it from a registry every time $logger = Zend_Registry::get(&#039;logger&#039;); &lt;br /&gt;&lt;a href=&quot;http://codenaked.org/archives/36-Dependency-Injection-Me-likey.html#extended&quot;&gt;Continue reading &quot;Dependency Injection: Me likey&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Tue, 29 Dec 2009 08:48:04 -0800</pubDate>
    <guid isPermaLink="false">http://codenaked.org/archives/36-guid.html</guid>
    
</item>
<item>
    <title>SOAP Kills</title>
    <link>http://codenaked.org/archives/29-SOAP-Kills.html</link>
            <category>PHP</category>
    
    <comments>http://codenaked.org/archives/29-SOAP-Kills.html#comments</comments>
    <wfw:comment>http://codenaked.org/wfwcomment.php?cid=29</wfw:comment>

    <slash:comments>2</slash:comments>
    <wfw:commentRss>http://codenaked.org/rss.php?version=2.0&amp;type=comments&amp;cid=29</wfw:commentRss>
    

    <author>nospam@example.com (Matthew Purdon)</author>
    <content:encoded>
    So I am working on a new assignment at work yesterday, should be a pretty simple task I think. I am consuming a SOAP service to get some simple data. &lt;strong&gt;Little did I know that it was such a pain to work with .Net when you are using the PHP SOAP extension&lt;/strong&gt;. I started out with the following WSDL (just a portion that I wanted to work with is listed).&lt;br /&gt;
&lt;textarea name=&quot;code&quot; class=&quot;XML&quot;&gt;
&lt;wsdl:binding name=&quot;WSHttpBinding_IFeedService&quot; type=&quot;i0:IFeedService&quot;&gt;
    &lt;wsp:PolicyReference URI=&quot;#WSHttpBinding_IFeedService_policy&quot;/&gt;
    &lt;soap12:binding transport=&quot;http://schemas.xmlsoap.org/soap/http&quot;/&gt;
    
    &lt;wsdl:operation name=&quot;List&quot;&gt;
        &lt;soap12:operation soapAction=&quot;http://schemas.example.com/IFeedService/List&quot; style=&quot;document&quot;/&gt;
        &lt;wsdl:input name=&quot;ListRequestMessage&quot;&gt;
            &lt;soap12:header message=&quot;i0:ListRequestMessage_Headers&quot; part=&quot;MetaRequest&quot; use=&quot;literal&quot;/&gt;
            &lt;soap12:body use=&quot;literal&quot;/&gt;
        &lt;/wsdl:input&gt;
        &lt;wsdl:output name=&quot;ListResponseMessage&quot;&gt;
            &lt;soap12:header message=&quot;i0:ListResponseMessage_Headers&quot; part=&quot;MetaResponse&quot; use=&quot;literal&quot;/&gt;
            &lt;soap12:body use=&quot;literal&quot;/&gt;
        &lt;/wsdl:output&gt;
    &lt;/wsdl:operation&gt;
    
    &lt;wsdl:operation name=&quot;ListByCode&quot;&gt;
        &lt;soap12:operation soapAction=&quot;http://schemas.example.com/IFeedService/ListByCode&quot; style=&quot;document&quot;/&gt;
        &lt;wsdl:input name=&quot;ListByCodeRequestMessage&quot;&gt;
            &lt;soap12:header message=&quot;i0:ListByCodeRequestMessage_Headers&quot; part=&quot;MetaRequest&quot; use=&quot;literal&quot;/&gt;
            &lt;soap12:body use=&quot;literal&quot;/&gt;
        &lt;/wsdl:input&gt;
        &lt;wsdl:output name=&quot;ListByCodeResponseMessage&quot;&gt;
            &lt;soap12:header message=&quot;i0:ListByCodeResponseMessage_Headers&quot; part=&quot;MetaResponse&quot; use=&quot;literal&quot;/&gt;
            &lt;soap12:body use=&quot;literal&quot;/&gt;
        &lt;/wsdl:output&gt;
    &lt;/wsdl:operation&gt;
&lt;/wsdl:binding&gt;

&lt;wsdl:binding name=&quot;BasicHttpBinding_IFeedService&quot; type=&quot;i0:IFeedService&quot;&gt;
    &lt;soap:binding transport=&quot;http://schemas.xmlsoap.org/soap/http&quot;/&gt;
    &lt;wsdl:operation name=&quot;List&quot;&gt;
        &lt;soap:operation soapAction=&quot;http://schemas.example.com/IFeedService/List&quot; style=&quot;document&quot;/&gt;
        &lt;wsdl:input name=&quot;ListRequestMessage&quot;&gt;
            &lt;soap:header message=&quot;i0:ListRequestMessage_Headers&quot; part=&quot;MetaRequest&quot; use=&quot;literal&quot;/&gt;
            &lt;soap:body use=&quot;literal&quot;/&gt;
        &lt;/wsdl:input&gt;
        &lt;wsdl:output name=&quot;ListResponseMessage&quot;&gt;
            &lt;soap:header message=&quot;i0:ListResponseMessage_Headers&quot; part=&quot;MetaResponse&quot; use=&quot;literal&quot;/&gt;
            &lt;soap:body use=&quot;literal&quot;/&gt;
        &lt;/wsdl:output&gt;
    &lt;/wsdl:operation&gt;
    &lt;wsdl:operation name=&quot;ListByCode&quot;&gt;
        &lt;soap:operation soapAction=&quot;http://schemas.example.com/IFeedService/ListByCode&quot; style=&quot;document&quot;/&gt;
        &lt;wsdl:input name=&quot;ListByCodeRequestMessage&quot;&gt;
            &lt;soap:header message=&quot;i0:ListByCodeRequestMessage_Headers&quot; part=&quot;MetaRequest&quot; use=&quot;literal&quot;/&gt;
            &lt;soap:body use=&quot;literal&quot;/&gt;
        &lt;/wsdl:input&gt;
        &lt;wsdl:output name=&quot;ListByCodeResponseMessage&quot;&gt;
            &lt;soap:header message=&quot;i0:ListByCodeResponseMessage_Headers&quot; part=&quot;MetaResponse&quot; use=&quot;literal&quot;/&gt;
            &lt;soap:body use=&quot;literal&quot;/&gt;
        &lt;/wsdl:output&gt;
    &lt;/wsdl:operation&gt;
&lt;/wsdl:binding&gt;
&lt;/textarea&gt;So I write up a quick test script to grab that WSDL and try to run a method on it. It looked something like this:&lt;br /&gt;
&lt;textarea name=&quot;code&quot; class=&quot;PHP&quot;&gt;
$wsdlUrl = &#039;http://eavdevscar01/core/ScarlettFeedServices.svc?wsdl&#039;;
$clientOptions = array(
    &#039;trace&#039;=&gt;true
);
$client = new MySoapClient($wsdlUrl, $clientOptions);

echo &quot;Functions:\n&quot;;
foreach ($client-&gt;__getFunctions() as $function) {
    echo $function,&quot;\n&quot;;
}

echo &quot;Types:\n&quot;;
foreach ($client-&gt;__getTypes() as $type) {
    echo $type,&quot;\n&quot;;
}

try {
    $params = array(
       &#039;NetworkCode&#039; =&gt; &#039;Test&#039;
    );

    $results = $client-&gt;List($params);
    print_r($results);
} catch (SoapFault $e) {
    print &quot;Call failed\n&quot;;
    print $client-&gt;__getLastRequestHeaders() . &quot;\n&quot;;
    print $client-&gt;__getLastRequest() . &quot;\n&quot;;
    print $client-&gt;__getLastResponseHeaders() . &quot;\n&quot;;
    print $client-&gt;__getLastResponse();
}
&lt;/textarea&gt;Easy-peasy, I have working with PHP driven SOAP services a bunch of times before so I could pretty much write that off the top of my head. So I run the code and I get a SoapFault saying that the Content-type is text/xml when it was expecting application/soap+xml. So I Google around and find that I have to specify the soap version 1.2 in order to get the correct Content-type. So I make the following change to $clientOptions:&lt;br /&gt;
&lt;textarea name=&quot;code&quot; class=&quot;PHP&quot;&gt;
$clientOptions = array(
    &#039;trace&#039;=&gt;true,
    &#039;soap_version&#039;=&gt;SOAP_1_2
);
&lt;/textarea&gt;Nice, that error is fixed. But Now I have another SoapFault: &quot;The SOAP action specified on the message, &#039;&#039;, does not match the HTTP SOAP Action. Google again. This time it looks like the PHP soap client is not able to deal with WSHTTP binding and must use the basicHTTP binding. I am not authenticating for this SOAP service, so I am not sure why it even matters. Luckily, the WSDL tells me that I have basicHTTP bindings available. When I try to use the basic data source though, I get another SoapFault &quot;Action /basic is not defined&quot;. So then I email the provider of the feed to make sure their basic binding is configured correctly and working. They make some changes and end up dropping the WSHTTP binding completely from the WSDL. Sweet, that error is fixed.&lt;br /&gt;
&lt;br /&gt;
Except that I am getting another SoapFault, fortunately for me I have run across it aready in my little adventure. It is now complaining that the Content-type application/soap+xml is incorrect as it was expecting text/xml. Seriously! So I go and remove the soap_version element from the $clientOptions array. Awesome, that was an easy one to fix!&lt;br /&gt;
&lt;br /&gt;
But now I have another SoapFault: &quot;Object reference not set to an instance of an object.&quot;. Google again. &lt;strong&gt;This is where things get really annoying&lt;/strong&gt;. First of all, the SoapFault error message is ridiculously cryptic. I find all kinds of forum posts and comments in the PHP manual about how you are supposed to pass parameters into the action method on your client. Here are some of the different versions that I tried:&lt;br /&gt;
&lt;textarea name=&quot;code&quot; class=&quot;PHP&quot;&gt;
    $params = array(
       &#039;Test&#039;
    );
    $results = $client-&gt;List($params);
&lt;/textarea&gt;No good.&lt;br /&gt;
&lt;textarea name=&quot;code&quot; class=&quot;PHP&quot;&gt;
    $params = array(
       &#039;NetworkCode&#039; =&gt; &#039;Test&#039;
    );
    $results = $client-&gt;ListByCode($params);
&lt;/textarea&gt;No good.&lt;br /&gt;
&lt;textarea name=&quot;code&quot; class=&quot;PHP&quot;&gt;
    $params = array(
       &#039;NetworkCode&#039; =&gt; &#039;Test&#039;
    );
    $results = $client-&gt;__soapCall(&#039;ListByCode&#039;, array($params));
&lt;/textarea&gt;No good.&lt;br /&gt;
&lt;textarea name=&quot;code&quot; class=&quot;PHP&quot;&gt;
    class ListByCodeRequest
    {
        public $NetworkCode = &#039;Test&#039;;
    }

    $params = new ListByCodeRequest();
    $results = $client-&gt;__soapCall(&#039;ListByCode&#039;, array($params));
&lt;/textarea&gt;No good. Then I tried adding &#039;classmap&#039; =&gt; array(&#039;ListByCode&#039;, &#039;ListByCodeRequest&#039;) to the $clientOptions array. That didn&#039;t work either. Please bear in mind that these changes may appear to be the flapping around of a dying fish, but I assure you that they each involved several minutes of Google research. I will admit though that by this point I was feeling fairly desperate. I decided to go get a copy of &lt;a href=&quot;http://www.soapui.org&quot; title=&quot;soapUI home page&quot;&gt;soapUI&lt;/a&gt; to see if maybe the feed itself wasn&#039;t working. I import the WSDL click on LIST and hit run. Bam! Results are returned immediately. I calmly stand up and leave my office before I bring violence upon my computer. &lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;15 minutes pass&lt;/em&gt;&lt;br /&gt;
&lt;br /&gt;
Okay, so I return to me desk and decide to look ONLY at the requests I was making and try to get them to match the ones created by soapUI. Here&#039;s what soapUI was doing:&lt;br /&gt;
&lt;textarea name=&quot;code&quot; class=&quot;XML&quot;&gt;
&lt;soapenv:Header/&gt;
&lt;soapenv:Body&gt;
  &lt;ns1:ListByCodeRequestMessage&gt;
     &lt;ns1:Request&gt;
        &lt;ns1:NetworkCode&gt;Test&lt;/ns1:NetworkCode&gt;
     &lt;/ns1:Request&gt;
  &lt;/ns1:ListByCodeRequestMessage&gt;
&lt;/soapenv:Body&gt;
&lt;/textarea&gt;And here is what I was producing:&lt;br /&gt;
&lt;textarea name=&quot;code&quot; class=&quot;XML&quot;&gt;
&lt;SOAP-ENV:Body&gt;
    &lt;ns1:ListByCodeRequestMessage/&gt;
&lt;/SOAP-ENV:Body&gt;
&lt;/textarea&gt;So obviously my parameters where not being passed in. I tried making the following change:&lt;br /&gt;
&lt;textarea name=&quot;code&quot; class=&quot;PHP&quot;&gt;
    $params = array(&#039;NetworkCode&#039;, &#039;Test&#039;);
    $results = $client-&gt;ListByCode($params);
&lt;/textarea&gt;Which results in this request:&lt;br /&gt;
&lt;textarea name=&quot;code&quot; class=&quot;XML&quot;&gt;
&lt;SOAP-ENV:Body&gt;
    &lt;ns1:ListByCodeRequestMessage/&gt;
    &lt;param1&gt;Test&lt;/param1&gt;
&lt;/SOAP-ENV:Body&gt;
&lt;/textarea&gt;Snap! I am getting a different SoapFault saying that param1 is basically an unknown parameter. I proceed to try several versions of nested arrays and finally give up after this one:&lt;br /&gt;
&lt;textarea name=&quot;code&quot; class=&quot;PHP&quot;&gt;
    $params = array(&#039;ListByCodeRequestMessage&#039;=&gt;array(&#039;Request&#039;=&gt;array(&#039;NetworkCode&#039;, &#039;Test&#039;)));
    $results = $client-&gt;ListByCode($params);
&lt;/textarea&gt;You see I am back to the whole &quot;Object reference not set to an instance of an object.&quot; SoapFault. It is then that lightening comes down and strikes my brain. This is the final (and working) version of the script:&lt;br /&gt;
&lt;textarea name=&quot;code&quot; class=&quot;PHP&quot;&gt;
$wsdlUrl = &#039;http://example.com/FeedServices.svc?wsdl&#039;;
$options = array(
    &#039;trace&#039;=&gt;true
);
$client = new SoapClient($wsdlUrl, $options);

class ListByCodeRequestMessage
{
    public $Request;
}

class Request
{
    public $NetworkCode;
}

try {
    $request = new Request();
    $request-&gt;NetworkCode = &#039;Test&#039;;

    $message = new ListByCodeRequestMessage();
    $message-&gt;Request = $request;

    $results = $client-&gt;ListByCode($message);
    print_r($results);
} catch (SoapFault $e) {
    echo &quot;Call failed\n&quot;;
    echo $client-&gt;__getLastRequestHeaders() . &quot;\n&quot;;
    echo $client-&gt;__getLastRequest() , &quot;\n\n&quot;;
    echo $client-&gt;__getLastResponseHeaders() . &quot;\n&quot;;
    echo $client-&gt;__getLastResponse(),&quot;\n\n&quot;;
}
&lt;/textarea&gt;So, hopefully this little saga will help others that are in danger of having a very long day as I had escape their fate. On a side note, whenever I am doing this kind of research on Google I always wish that there was an option to specify how old the results should be. I have the option Search: [ ] the web [ ] page from Canada, but I&#039;d really like to see [ ] from this month [ ] from this year [ ] any time as options as well. A blog post mentioning PHP and SOAP from 2003 is probably not going to be helpful. Although sometimes I can see the date it was written before I click, not seeing the entry at all would be great.&lt;br /&gt;
 
    </content:encoded>

    <pubDate>Fri, 20 Feb 2009 06:06:18 -0800</pubDate>
    <guid isPermaLink="false">http://codenaked.org/archives/29-guid.html</guid>
    
</item>
<item>
    <title>Enterprisey PHP</title>
    <link>http://codenaked.org/archives/28-Enterprisey-PHP.html</link>
            <category>PHP</category>
    
    <comments>http://codenaked.org/archives/28-Enterprisey-PHP.html#comments</comments>
    <wfw:comment>http://codenaked.org/wfwcomment.php?cid=28</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://codenaked.org/rss.php?version=2.0&amp;type=comments&amp;cid=28</wfw:commentRss>
    

    <author>nospam@example.com (Matthew Purdon)</author>
    <content:encoded>
    I hear a lot of talk about the use of PHP in the Enterprise, recently there was even a white paper circulated extolling the virtues of PHP and attempting to make the case that PHP should be the language of choice for Enterprise development. Although the paper does bring up some interesting points such as the large number of extensions and the fact that there are a number of bridges for PHP to load native code written in Java and other languages, taking away from these strengths was that there is way too much emphasis placed on how many websites run PHP. Although it is hard to argue with the fact that PHP is greatly suited to web development, that in no way translates into suitability for Enterprise development. No offense to the language, but &lt;strong&gt;I find it perfectly understandable that PHP is not often considered a language suitable for Enterprise development&lt;/strong&gt;.&lt;br /&gt;
&lt;br /&gt;
PHP developers have a love-hate relationship with Java. Many PHP&#039;ers are quick to point out that &quot;&lt;a href=&quot;http://phpadvent.org/2008/php-is-not-java-by-luke-welling&quot;&gt;PHP is not Java&lt;/a&gt;&quot; and yet when one considers some of the most recent waves in PHP interest, they are frequently things that have been around in the Java world for years and are just now being introduced into PHP. A couple of recent examples are the sudden surge in &lt;a href=&quot;http://phpunit.de&quot;&gt;PHPUnit&lt;/a&gt; and &lt;a href=&quot;http://phpundercontrol.org&quot;&gt;phpUnderControl&lt;/a&gt;. The latter isn&#039;t even a fully native PHP solution but en extension of the venerable Cruise Control continuous integration suite. That being said, I use both of those extensively and they form a crucial part of my software development process. Unfortunately, I feel that the adoption of these technologies has started to plateau as the initial wave of blog posts and general buzz have died down. Many PHPers feel that it&#039;s just too much effort for what it&#039;s worth. This is the key to the whole debate in my opinion. PHP developers put everything behind speed when it comes to development, in fact I often see bad code decisions being made for the benefits of a few CPU cycles. Perhaps it&#039;s because the speed of PHP is the primary strength that developers point to when comparing it to other languages that they focus on that feature. Honestly, &lt;strong&gt;PHP should be the fastest language on the web, after all it&#039;s all it&#039;s done for the last decade&lt;/strong&gt;.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what you should take away from this post:&lt;br /&gt;
1) Using PHP does not &lt;a href=&quot;http://phpadvent.org/2008/why-using-php-makes-you-cooler-by-elizabeth-naramore&quot;&gt;make you cooler&lt;/a&gt;. It should mean that you have chosen the right tool for the job. There is a reason why Zend Studio (from Zend, &lt;u&gt;The&lt;/u&gt; PHP Company) is written in Java and not PHP-GTK. Why be just a PHP developer when you can be a programmer with many tools at your disposal.&lt;br /&gt;
2) If you want to improve the way PHP is considered in terms of The Enterprise, make your code look like it was written for the Enterprise. Stop considering your software to be something that you will write and throw away. Write it like it&#039;s something you will have to maintain for a decade and some day you just might get to.&lt;br /&gt;
 
    </content:encoded>

    <pubDate>Thu, 29 Jan 2009 06:58:59 -0800</pubDate>
    <guid isPermaLink="false">http://codenaked.org/archives/28-guid.html</guid>
    
</item>
<item>
    <title>Debugging with FirePHP</title>
    <link>http://codenaked.org/archives/12-Debugging-with-FirePHP.html</link>
            <category>PHP</category>
    
    <comments>http://codenaked.org/archives/12-Debugging-with-FirePHP.html#comments</comments>
    <wfw:comment>http://codenaked.org/wfwcomment.php?cid=12</wfw:comment>

    <slash:comments>3</slash:comments>
    <wfw:commentRss>http://codenaked.org/rss.php?version=2.0&amp;type=comments&amp;cid=12</wfw:commentRss>
    

    <author>nospam@example.com (Matthew Purdon)</author>
    <content:encoded>
    One of the nicest features to have when you are developing an application is a decent debug console so that you can see what your application is doing without having to look through ten log files and put var_dumps that you have to comment out all through your code. In the &lt;a href=&quot;http://framework.zend.com&quot;&gt;Zend Framework&lt;/a&gt; v1.6 we get a new feature based on &lt;a href=&quot;http://www.firephp.org&quot;&gt;FirePHP&lt;/a&gt; which will allow us to log directly to the Firebug console with a simple API call from PHP. Here is an example of how this looks in my application:&lt;br /&gt;
&lt;br /&gt;
&lt;!-- s9ymdb:9 --&gt;&lt;img width=&quot;728&quot; height=&quot;485&quot; style=&quot;border: 0px; padding-left: 5px; padding-right: 5px;&quot; src=&quot;http://codenaked.org/uploads/firebug.jpg&quot; alt=&quot;&quot; /&gt; &lt;br /&gt;&lt;a href=&quot;http://codenaked.org/archives/12-Debugging-with-FirePHP.html#extended&quot;&gt;Continue reading &quot;Debugging with FirePHP&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Fri, 12 Sep 2008 06:40:00 -0700</pubDate>
    <guid isPermaLink="false">http://codenaked.org/archives/12-guid.html</guid>
    
</item>
<item>
    <title>Better Alternatives to using Zend_Registry</title>
    <link>http://codenaked.org/archives/16-Better-Alternatives-to-using-Zend_Registry.html</link>
            <category>PHP</category>
    
    <comments>http://codenaked.org/archives/16-Better-Alternatives-to-using-Zend_Registry.html#comments</comments>
    <wfw:comment>http://codenaked.org/wfwcomment.php?cid=16</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://codenaked.org/rss.php?version=2.0&amp;type=comments&amp;cid=16</wfw:commentRss>
    

    <author>nospam@example.com (Matthew Purdon)</author>
    <content:encoded>
    Don&#039;t get me wrong, I think the Zend_Registry component is great. &lt;strong&gt;There are a couple of problems that I see when using the Zend_Registry as a container&lt;/strong&gt; for junk like database connection objects and session namespaces and pretty much every other resource that you need to be globally accessible. The first, is that there is no information about what kinds of resources are available to you when you are using the registry. In other words, there is no way to know what Zend_Registry::get(&#039;db&#039;); is actually going to give you. Is it a Database connection resource or is it a Data Buffer? Actually, it almost makes more sense for &quot;db&quot; to be an acronym for data buffer ... At any rate, there is no way to enforce what you are getting. This means that your editor can&#039;t code hint for you and your API docs don&#039;t really show an object that has the responsibility of wrangling application resources. I guess that is a good summary for the first issue with Zend_Registry - &lt;strong&gt;it&#039;s too generic to be really useful&lt;/strong&gt;.&lt;br /&gt;
&lt;br /&gt;
The second problem with the Zend_Registry is that it is essentially a global array. At any given time an innocent developer can unwittingly blow away your database connection with his data buffer and there is nothing to stop him. We all know (or should know) that global variables are bad. They inject uncertainty into our applications and can be the cause of some of the most irritating to debug problems. So, to sum up the second issue with Zend_Registry - &lt;strong&gt;it suffers from the same issues that all global variables suffer&lt;/strong&gt;.&lt;br /&gt;
&lt;br /&gt;
So, how do we fix it. Simple really, we create an object that is responsible for maintaining these application services. In fact, I use two different objects to manage two different types of application resource. I use Naked_App_Environment to manage configuration and environment information and I use Naked_App_Workspace to manage my application resources such as Naked_Db connections and Zend_Logger instances. Let&#039;s take a look at these two components and see how your life as a developer can be made better... &lt;br /&gt;&lt;a href=&quot;http://codenaked.org/archives/16-Better-Alternatives-to-using-Zend_Registry.html#extended&quot;&gt;Continue reading &quot;Better Alternatives to using Zend_Registry&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Wed, 10 Sep 2008 14:21:32 -0700</pubDate>
    <guid isPermaLink="false">http://codenaked.org/archives/16-guid.html</guid>
    
</item>
<item>
    <title>Adding a profiler to a Db class.</title>
    <link>http://codenaked.org/archives/13-Adding-a-profiler-to-a-Db-class..html</link>
            <category>PHP</category>
    
    <comments>http://codenaked.org/archives/13-Adding-a-profiler-to-a-Db-class..html#comments</comments>
    <wfw:comment>http://codenaked.org/wfwcomment.php?cid=13</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://codenaked.org/rss.php?version=2.0&amp;type=comments&amp;cid=13</wfw:commentRss>
    

    <author>nospam@example.com (Matthew Purdon)</author>
    <content:encoded>
    First of all, in case you don&#039;t know me that well, you need to know that I am &lt;strong&gt;a big fan of unit testing&lt;/strong&gt;. Although I like the idea of using a database abstraction layer, I have come to dislike PDO for several reasons. First of all it&#039;s behavior is not the same for every database driver that you use. This is not a fault of PDO itself so much as the authors of the database specific drivers that are not able to implement the entire feature set. Secondly, I am not sure I buy into this &quot;You can just switch databases and all you have to do is change the config&quot; argument. Any application that either has a DBA on the team or cares at all about performance will have tailored SQL to get the most out of the database - which as you know tends to be the main bottleneck in an application. The main reason that I dislike PDO is that it is such a pain to mock it while unit testing. For some reason it was deemed necessary to have PDO connect on construct rather than either having an explicit connect() method or a lazy connect when one is needed. Even though you can specify that you don&#039;t run the constructor when you mock PDO, you then run into internal trouble as some settings are not set up properly and you get errors. At work, I tend to just wrap PDO with my own Db class that proxies calls to the internal PDO instance so that I can mock my Db class and everything plays nicely.&lt;br /&gt;
&lt;br /&gt;
For my own junk, I tend to always go with MySQL as my database so I don&#039;t really like the idea of adding a wrapper to a wrapper to a wrapper in order to talk to it. I use MySQLi as my db class, but I still wrap it so that I can do lazy connects. The reason for this is so that once my cache is warmed up, and the user has logged in, I &lt;strong&gt;don&#039;t even connect to the database during a normal session&lt;/strong&gt;. This helps tremendously as the connection to the database is the most expensive part of database interaction. If I do need to perform any write operations, they are performed by the Unit of Work, which doesn&#039;t kick in until the dipatchLoopShutdown. (I still have a few tweaks in regards to caching with my Unit of Work implementation before I show you how that works.) This also helps to ensure that if I do need to open a connection, it&#039;s for the shortest amount of time possible. &lt;br /&gt;&lt;a href=&quot;http://codenaked.org/archives/13-Adding-a-profiler-to-a-Db-class..html#extended&quot;&gt;Continue reading &quot;Adding a profiler to a Db class.&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Mon, 18 Aug 2008 06:09:54 -0700</pubDate>
    <guid isPermaLink="false">http://codenaked.org/archives/13-guid.html</guid>
    
</item>
<item>
    <title>Wrap PDO and be happy.</title>
    <link>http://codenaked.org/archives/11-Wrap-PDO-and-be-happy..html</link>
            <category>PHP</category>
    
    <comments>http://codenaked.org/archives/11-Wrap-PDO-and-be-happy..html#comments</comments>
    <wfw:comment>http://codenaked.org/wfwcomment.php?cid=11</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://codenaked.org/rss.php?version=2.0&amp;type=comments&amp;cid=11</wfw:commentRss>
    

    <author>nospam@example.com (Matthew Purdon)</author>
    <content:encoded>
    So I normally don&#039;t bother using PDO as most of my projects are MySQL based, for a project at work though it was decided to use it. One thing that I get really annoyed with is the fact that PDO attempts to connect on instantiation. I have no idea why you would want that to be the default behavior as it makes so many things a pain. Where it really bites you is in unit testing because it&#039;s very difficult to mock PDO.&lt;br /&gt;
&lt;br /&gt;
So, instead of using PDO directly I wrap it with my own class that defers instantiating PDO until absolutely necessary.  In this way, I can mock my database class quite easily so that I can test without touching the database. So let&#039;s take a look at some code... &lt;br /&gt;&lt;a href=&quot;http://codenaked.org/archives/11-Wrap-PDO-and-be-happy..html#extended&quot;&gt;Continue reading &quot;Wrap PDO and be happy.&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Wed, 30 Jul 2008 09:31:06 -0700</pubDate>
    <guid isPermaLink="false">http://codenaked.org/archives/11-guid.html</guid>
    
</item>
<item>
    <title>Zend Framework Exception Handling</title>
    <link>http://codenaked.org/archives/9-Zend-Framework-Exception-Handling.html</link>
            <category>PHP</category>
    
    <comments>http://codenaked.org/archives/9-Zend-Framework-Exception-Handling.html#comments</comments>
    <wfw:comment>http://codenaked.org/wfwcomment.php?cid=9</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://codenaked.org/rss.php?version=2.0&amp;type=comments&amp;cid=9</wfw:commentRss>
    

    <author>nospam@example.com (Matthew Purdon)</author>
    <content:encoded>
    Handling exceptions is extremely import if you want to have an application that is stable and end-user friendly. The &lt;a href=&quot;http://framework.zend.com&quot; title=&quot;Framework Home Page&quot;&gt;Zend Framework&lt;/a&gt; comes with some great features for handling things like missing controllers and actions right out of the box. Like many things with the Zend Framework, you have to dig a little before you find the answers that you need. There are three steps needed to take advantage of the build in exception handling features:&lt;br /&gt;
&lt;br /&gt;
1) You have to register the &lt;a href=&quot;http://framework.zend.com/manual/en/zend.controller.plugins.html#zend.controller.plugins.standard.errorhandler&quot; title=&quot;ZF Manual&quot;&gt;Zend_Controller_Plugin_ErrorHandler&lt;/a&gt; plugin.&lt;br /&gt;
2) You have to create an error controller&lt;br /&gt;
3) You have to create the templates for the specific error types&lt;br /&gt;
&lt;br /&gt;
Read on to see what my versions of the above look like... &lt;br /&gt;&lt;a href=&quot;http://codenaked.org/archives/9-Zend-Framework-Exception-Handling.html#extended&quot;&gt;Continue reading &quot;Zend Framework Exception Handling&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Fri, 20 Jun 2008 18:32:16 -0700</pubDate>
    <guid isPermaLink="false">http://codenaked.org/archives/9-guid.html</guid>
    
</item>
<item>
    <title>Simple array syntax</title>
    <link>http://codenaked.org/archives/8-Simple-array-syntax.html</link>
            <category>PHP</category>
    
    <comments>http://codenaked.org/archives/8-Simple-array-syntax.html#comments</comments>
    <wfw:comment>http://codenaked.org/wfwcomment.php?cid=8</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://codenaked.org/rss.php?version=2.0&amp;type=comments&amp;cid=8</wfw:commentRss>
    

    <author>nospam@example.com (Matthew Purdon)</author>
    <content:encoded>
    So I was reading &lt;a href=&quot;http://brian.moonspot.net/2008/05/28/short-array-syntax-for-php&quot; title=&quot;Short array syntax article&quot;&gt;Brian Moon&#039;s blog&lt;/a&gt; today. I had bookmarked it to come back to it later but then I had to go to NY and everything... Turns out the change was voted down. The vote by email thing is lame as well.&lt;br /&gt;
&lt;br /&gt;
So here&#039;s my opinion. Anything that makes PHP feel more like a modern programming language is better. What is the percentage of programmers that still code in C? Just because PHP is built on top of C doesn&#039;t mean that it has to look and feel like C. I totally agreed with Brian that it should be committed. In fact, I think the syntax should be expanded to include ranges:&lt;br /&gt;
&lt;br /&gt;
$foo = [1,2,3,4,5];&lt;br /&gt;
&lt;br /&gt;
could be written as:&lt;br /&gt;
&lt;br /&gt;
$foo = [1..5];&lt;br /&gt;
&lt;br /&gt;
Sweet. Oh and for the love of God can you make functions as first class citizens so we can start to do some functional programming?&lt;br /&gt;
&lt;br /&gt;
*sigh* PHP is held back again. 
    </content:encoded>

    <pubDate>Wed, 18 Jun 2008 18:38:46 -0700</pubDate>
    <guid isPermaLink="false">http://codenaked.org/archives/8-guid.html</guid>
    
</item>
<item>
    <title>Object Property Visibility and Magic Methods</title>
    <link>http://codenaked.org/archives/7-Object-Property-Visibility-and-Magic-Methods.html</link>
            <category>PHP</category>
    
    <comments>http://codenaked.org/archives/7-Object-Property-Visibility-and-Magic-Methods.html#comments</comments>
    <wfw:comment>http://codenaked.org/wfwcomment.php?cid=7</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://codenaked.org/rss.php?version=2.0&amp;type=comments&amp;cid=7</wfw:commentRss>
    

    <author>nospam@example.com (Matthew Purdon)</author>
    <content:encoded>
    I often thought that one of the great features of OOP in PHP 5 was the addition of the public, protected and private keywords. Now, I find that they are &lt;strong&gt;total pain in the ass&lt;/strong&gt; when used incorrectly. I was just reading the article on DevShed about &lt;a href=&quot;http://www.devshed.com/c/a/PHP/Protecting-PHP-5-Class-Data-with-Member-Visibility&quot; title=&quot;DevShed article&quot;&gt;protecting class data with member visibility&lt;/a&gt; and I was reminded of an email that I had sent out to the PHP developers that I work with. As usual, there was not one response to the idea of using magic methods rather than fifty eleven accessors and mutators. I personally use the magic __get and __set methods all of the time but I&#039;ll get to that in a minute. &lt;br /&gt;&lt;a href=&quot;http://codenaked.org/archives/7-Object-Property-Visibility-and-Magic-Methods.html#extended&quot;&gt;Continue reading &quot;Object Property Visibility and Magic Methods&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Sun, 08 Jun 2008 10:12:31 -0700</pubDate>
    <guid isPermaLink="false">http://codenaked.org/archives/7-guid.html</guid>
    
</item>

</channel>
</rss>