<?xml version="1.0"?>
<rss version="2.0">
  <channel>
    <title>PHPDeveloper.org</title>
    <link>http://www.phpdeveloper.org</link>
    <description>Up-to-the Minute PHP News, views and community</description>
    <language>en-us</language>
    <pubDate>Wed, 23 May 2012 19:36:12 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Michael Nitschinger's Blog: A primer on PHP exceptions]]></title>
      <guid>http://www.phpdeveloper.org/news/17994</guid>
      <link>http://www.phpdeveloper.org/news/17994</link>
      <description><![CDATA[<p>
<i>Michael Nitschinger</i> has a new post focusing on one of the more commonly used, but maybe just as commonly misunderstood, part of PHP - <a href="http://nitschinger.at/A-primer-on-PHP-exceptions">exceptions and their handling</a>. His latest post looks at what Exceptions in PHP have to offer and provides some "best practices" in their use.
</p>
<blockquote>
Exceptions are and should be an integral part of any general purpose programming language. PHP introduced them long ago (with the release of PHP 5 or 5.1), but it still seems that many of the concepts are not fully understood or ignored by the community. This post aims to be a solid introduction to exception architecture, handling and testing. At the end of the post you should be able to know when to raise an exception and how it should look like.
</blockquote>
<p>
He talks about situations when (and when not) to use exceptions, normalizing them for easier try/catch-ing and includes the exception class hierarchy, including the types pulled from the <a href="http://php.net/spl">SPL</a>. He shows examples (based on the <a href="http://lithify.me/">Lithium</a> framework's namespacing)  how to create "namespaced exceptions" and how to use these in a bit of sample code. He also mentions the use of the custom <a href="http://us.php.net/manual/en/class.errorexception.php">error handling with the ErrorException</a> as well as a quick look at testing these basic and custom exceptions correctly (PHPUnit-based tests).
</p>]]></description>
      <pubDate>Wed, 23 May 2012 09:17:41 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Stefan Koopmanschap's Blog: Using custom namespaces with (C/S)ilex and Composer]]></title>
      <guid>http://www.phpdeveloper.org/news/17810</guid>
      <link>http://www.phpdeveloper.org/news/17810</link>
      <description><![CDATA[<p>
<i>Stefan Koopmanschap</i> has a quick new post to his blog with <a href="http://www.leftontheweb.com/message/Using_custom_namespaces_with_CSilex_and_Composer">a handy tip for Composer and Cilex/Silex users</a> when dealing with custom namespaces.
</p>
<blockquote>
For a new proof of concept application I'm building, I need both a simple web interface as well as some commandline tools. I decided to use Silex for the web interface and Cilex for the CLI tools, and opted for using Composer for installing these dependencies into my project. I ran into some issues with the custom project libraries I was building for this application however. Registering my custom namespace into Silex and Cilex didn't result in the classes being loaded for some reason. Composer helped me out though.
</blockquote>
<p>
His solution involves letting Composer be the default autoloader for the application via an "autoloader" configuration option in the "composer.json"  (that can also take a classmap option if you're not PSR-0 compliant, <a href="http://getcomposer.org/doc/04-schema.md#autoload">see here</a>).
</p>]]></description>
      <pubDate>Thu, 12 Apr 2012 12:22:47 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Rob Allen's Blog: A primer on PHP namespaces]]></title>
      <guid>http://www.phpdeveloper.org/news/17549</guid>
      <link>http://www.phpdeveloper.org/news/17549</link>
      <description><![CDATA[<p>
For those that either haven't worked much with PHP 5.3 in their applications (or just haven't gotten around to using the feature) <i>Rob Allen</i> has <a href="http://akrabat.com/php/a-primer-on-php-namespaces/">put together an introduction to namespaces</a> to guide you through some first steps and share some example usage.
</p>
<blockquote>
I know that there are a lot of posts now about namespaces in PHP 5.3. This is mine which is how I learnt how they work. [...] That is, namespaces allow us to: combine libraries with the same classnames, avoid very long classnames and organise our code easily. Note that namespaces do not just affect classes. They also affect functions and constants.
</blockquote>
<p>
He starts with the basic namespace definition (using the "namespace" keyword), shows how to import another namespace with "use" and the use of the __NAMESPACE__ constant to determine what namespace you're operating in. More information on namespaces can be found <a href="http://php.net/manual/en/language.namespaces.rationale.php">in the PHP manual</a>.
</p>]]></description>
      <pubDate>Thu, 16 Feb 2012 08:25:43 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPMaster.com: Autoloading in PHP and the PSR-0 Standard]]></title>
      <guid>http://www.phpdeveloper.org/news/17534</guid>
      <link>http://www.phpdeveloper.org/news/17534</link>
      <description><![CDATA[<p>
On PHPMaster.com today there's a new tutorial <a href="http://phpmaster.com/autoloading-and-the-psr-0-standard/">introducing you to the PSR-0 standard</a> and how it effects the autoloading in many PHP applications and frameworks. Specifically, they show how it's implemented in a <a href="http://symfony.com">Symfony2</a> component
</p>
<blockquote>
In this article I'll walk you through the "history of autoloading," from the older to the current PSR-0 standard autoloader approach found in many PHP frameworks such as Lithium, Symfony, Zend, etc. Then I will introduce you to the ClassLoader component from the Symfony2 project for PHP 5.3 which follows the PSR-0 standard.
</blockquote>
<p>
He starts with a look at a basic "__autoload" function call that looks in a directory for libraries. Improving on that, he makes two methods for loading - one for controllers, the other for models - and a loader that splits on the "_" character and determines the path from there.
</p>
<p>
Even this isn't PSR-0, though, so he shows how using namespace information, you can load classes in a unified way. He shows how to implement this with a loader that's already well-developed and ready for use - the Symfony ClassLoader component. They show how to register namespaces, prefixes as well as use the APC functionality to manually store/fetch the APC version of the loaded file's opcodes.
</p>]]></description>
      <pubDate>Mon, 13 Feb 2012 12:29:24 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Larry Garfield's Blog: PHP project structure survey]]></title>
      <guid>http://www.phpdeveloper.org/news/17401</guid>
      <link>http://www.phpdeveloper.org/news/17401</link>
      <description><![CDATA[<p>
<i>Larry Garfield</i> has posted the results of some of his research into popular PHP frameworks and projects and <a href="http://www.garfieldtech.com/blog/php-project-structure">see how they handle their structure</a> as it relates to the PSR-0 standard.
</p>
<blockquote>
As <a href="http://drupal.org/">Drupal</a> is in the process of considering how to restructure code to best leverage the PSR-0 standard, I figured it would be wise to take a quick survey of how some other major projects organize their code bases. This is not a complete rundown of every project, simply roughly comparable notes for those areas Drupal is currently discussing. I am posting it here in the hopes that it will be useful to more than just Drupal.
</blockquote>
<p>The projects he looked to for his examples were:</p>
<ul>
<li><a href="http://cakephp.org/">CakePHP</a>
<li><a href="http://symfony.com/">Symfony2</a>
<li><a href="http://silex.sensiolabs.org/">Silex</a>
<li><a href="http://codeigniter.com/">CodeIgniter</a>
<li><a href="https://github.com/zendframework/zf2">Zend Framework 2</a>
<li><a href="http://packagist.org/">Composer</a>
</ul>]]></description>
      <pubDate>Mon, 16 Jan 2012 13:08:38 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Fabien Potencier's Blog: Create your own framework... on top of the Symfony2 Components (part 7)]]></title>
      <guid>http://www.phpdeveloper.org/news/17396</guid>
      <link>http://www.phpdeveloper.org/news/17396</link>
      <description><![CDATA[<p>
<i>Fabien Potencier</i> has posted the <a href="http://fabien.potencier.org/article/56/create-your-own-framework-on-top-of-the-symfony2-components-part-7">seventh part</a> of his series looking at how to make a custom framework on top of the components from the <a href="http://symfony.com">Symfony2</a> framework. In this part of the series he improves his basic framework by adding some namespacing to organize the application a bit more.
</p>
<blockquote>
If you have a closer look at the code, front.php has one input, the Request, and one output, the Response. Our framework class will follow this simple principle: the logic is about creating the Response associated with a Request. As the Symfony2 components requires PHP 5.3, let's create our very own namespace for our framework: Simplex.
</blockquote>
<p>
He puts the main front controller in just the "Simplex" namespace but adds in others for the controllers and models. He also updates his Composer configuration to create some PSR-0 autoloading.
</p>]]></description>
      <pubDate>Mon, 16 Jan 2012 08:46:22 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Chris Hartjes' Blog: Scope Is Not a Mouthwash]]></title>
      <guid>http://www.phpdeveloper.org/news/17175</guid>
      <link>http://www.phpdeveloper.org/news/17175</link>
      <description><![CDATA[<p>
<i>Chris Hartjes</i> has a reminder posted to his blog today in the form of <a href="http://www.littlehart.net/atthekeyboard/2011/11/25/scope-is-not-mouthwash/">this recent post</a> that "scope is not a mouthwash" - personal experience from his recent development where he forgot about something as simple as scoping (and it caused him all sorts of headaches).
</p>
<blockquote>
For [a chapter in my book on dependency injection] I am using <a href="http://pimple.sensiolabs.org/">Pimple</a>, an incredibly small but effective dependency injection container. Easy to use, simple and effective documentation, just what I was looking for. I also noticed that Pimple supported the use of closures (or anonymous functions) as a way of storing a dependency. Then things got stupid.
</blockquote>
<p>
He shares a bit of code showing how he added it to his bootstrap but was given a "cannot find class" error when he tried to use the tool. He walks through the steps he followed to track down the problem - looking closer at Pimple, investigating closures and, the ultimate problem, namespace scoping. He was missing a "" to start his namespace and closures work slightly differently:
</p>
<blockquote>
So why does it behave differently inside closures? I am not 100% sure, but if I had to make an educated guess I would say that when trying to resolve namespaces inside a closure, the interpretor doesn't assume that it is already inside the global namespace, that it is in a namespace of it's own.
</blockquote>]]></description>
      <pubDate>Mon, 28 Nov 2011 09:50:03 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPMaster.com: PHP Namespaces]]></title>
      <guid>http://www.phpdeveloper.org/news/17019</guid>
      <link>http://www.phpdeveloper.org/news/17019</link>
      <description><![CDATA[<p>
One of the features that's recently been introduced into the PHP language has been a feature for keeping code not only more organized, but more modular - namespacing (PHP 5.3+). In <a href="http://phpmaster.com/php-namespaces/">this new tutorial</a> from PHPMaster.com they introduce you to this handy feature and include a bit of code showing their use.
</p>
<blockquote>
Namespaces were a long awaited feature in PHP. While many other important features were released with PHP 5, namespaces were not supported until version 5.3. This led to various techniques for emulating them which, though necessary, were messy and confusing. Although namespaces have been part of PHP for over a year now, such techniques still exist. Many developers simply don't know how to use proper namespaces in their code. In this article I will explain why namespaces are important and how you can use them in your own PHP code.
</blockquote>
<p>
He starts off by talking about what namespaces are and how they can be used to segment up applications, especially larger ones, into more manageable chunks. Basic code is included showing how to implement a namespace, referencing items inside a namespace, the "use" keyword and the __NAMESPACE__ magic variable.
</p>]]></description>
      <pubDate>Thu, 20 Oct 2011 09:24:47 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPBuilder.com: Introducing Namespaces for PHP Developers]]></title>
      <guid>http://www.phpdeveloper.org/news/16893</guid>
      <link>http://www.phpdeveloper.org/news/16893</link>
      <description><![CDATA[<p>
On PHPBuilder.com today there's a new article from <i>Jason Gilmore</i> <a href="http://www.phpbuilder.com/columns/intro_namespaces/Introducing_Namespaces_Gilmore_09-20-2011.php3">introducing you to namespaces</a> in PHP 5.3+ development. Namespaces make it simpler to separate out your code into functional pieces and help keep it organized.
</p>
<blockquote>
The inclusion of namespace support within PHP 5.3 effectively brought the need for gripes and workarounds to a halt, however adoption of this exciting new feature has seemed surprisingly slow in the more than two years since its release. [...] The utility of this new feature is simply undeniable. Therefore I thought it would be worthwhile to offer a formal introduction to namespaces for the benefit of those PHP developers who haven't yet had the opportunity to investigate the topic.
</blockquote>
<p>
He starts by introducing the concept of a "namespace" as a sort of container for your code, providing separation that prevents errors like the infamous "cannot redeclare class" issue. He includes examples of PHP's namespace syntax to split out two "Account" classes into two different sections. Using them is as easy as referring to them by their namespaced "path" or using something like the "use" keyword to reassign it to another name.
</p>]]></description>
      <pubDate>Thu, 22 Sep 2011 10:13:05 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Ralph Schindler's Blog: Autoloading (Revisited)]]></title>
      <guid>http://www.phpdeveloper.org/news/16880</guid>
      <link>http://www.phpdeveloper.org/news/16880</link>
      <description><![CDATA[<p>
<i>Ralph Schindler</i> has a new post to his today looking back at a sort of <a href="http://ralphschindler.com/2011/09/19/autoloading-revisited">history of autoloading</a> and some of what we've learned even in just the journey from PHP 5.0 to 5.3 (and has become best practice in the community).
</p>
<blockquote>
It wasn't until years later that certain best practices had emerged and the prolific usage of require_once/include_once throughout large bodies of code had started drying up. Even after autoloading had been adopted by larger more visible projects, a common patten had yet to emerge. [...]  Fast-forward to today, and we see that this standard for autoloading has agreed upon by a large number of projects and has come to be named the "PSR-0 autoloading standard".
</blockquote>
<p>
He covers some of the things we (the development community) have learned about autoloading and resources in our applications. He talks about the <a href="https://github.com/weierophinney/zf2/blob/master/bin/classmap_generator.php">classmap tool</a> that <i>Matthew Weier O'Phinney</i> developed (and some of its downfalls) as well as a move into PHP namespacing that has helped to make some of the "namespacing" based on class names obsolete. He's noticed a pattern in namespacing already - a self-contained structure that provides more of a "drop in" solution and how that's handled in the code.
</p>]]></description>
      <pubDate>Tue, 20 Sep 2011 09:18:55 -0500</pubDate>
    </item>
  </channel>
</rss>

