<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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:series="http://unfoldingneurons.com/"
		>
<channel>
	<title>Comments on: Making Life Better With The SPL Autoloader</title>
	<atom:link href="http://www.brandonsavage.net/making-life-better-with-the-spl-autoloader/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brandonsavage.net/making-life-better-with-the-spl-autoloader/</link>
	<description>The personal blog of Brandon Savage. Contains entries of a personal and professional nature focusing on PHP, Apple, LAMP, MySQL and Washington, DC.</description>
	<lastBuildDate>Thu, 29 Jul 2010 11:09:38 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: David Stockton</title>
		<link>http://www.brandonsavage.net/making-life-better-with-the-spl-autoloader/#comment-900</link>
		<dc:creator>David Stockton</dc:creator>
		<pubDate>Wed, 12 Aug 2009 06:29:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=492#comment-900</guid>
		<description>@iflyhigh:


- I agree that explicit imports show what files your code relies on, that doesn&#039;t necessarily translate to classes.  With a good autoloading strategy (ie, one class per file, and having the class name correspond to the location and name of the class) it&#039;s very easy to figure out what classes you&#039;re using.  
- Large codebases get confusing real fast if there is not a defined mapping of how to name files and classes.  If you&#039;ve got two different &quot;Account&quot; classes and don&#039;t have them either namespaced or class prefixed, you&#039;re probably going to have problems anyway.
- The stat call is something you&#039;ve got to do explicitly in your autoloader if that&#039;s the behavior you want.  It&#039;s not required.  Zend Framework&#039;s autoloader up until 1.8 didn&#039;t use a stat call.  It just did a require on the code which meant 2 things...  First it was faster since it didn&#039;t have a stat call, but second, if you were stacking autoloaders, the Zend loader would need to be done last since require will bomb if the file doesn&#039;t exist.  The current version lets you configure this behavior.

Say perhaps you&#039;re writing code using a strategy pattern.  The code to provide that strategy is determined at run-time.  If you go with the autoload way of doing things, only the classes and interfaces you need will be loaded.  If you go with require[_once], you&#039;ll be including all the classes all the time, even if they aren&#039;t needed.  That adds parsing and memory overhead.  If you go with include[_once] and only load the classes right before they are needed, you&#039;ve no longer got the benefit of having all the classes you&#039;re using in one place (typically the top of the file), and if it&#039;s critical those files be loaded, include[_once] isn&#039;t going to bail if there was a problem loading.

- Lastly, who says lazy cannot be right?  I think the benefits of using autoloader(s) greatly outweigh the downsides.  The benefits are there both for the developer (not having to jump up to the top to include a new class for another file), the performance (only including files that are requested, even if the code may have references to other classes on non-executed lines).  Additionally, as Brandon mentioned, new classes don&#039;t need to be registered somewhere.  If you have any code that dynamically generates classes that may or may not actually exist, this can be a huge benefit.</description>
		<content:encoded><![CDATA[<p>@iflyhigh:</p>
<p>- I agree that explicit imports show what files your code relies on, that doesn&#8217;t necessarily translate to classes.  With a good autoloading strategy (ie, one class per file, and having the class name correspond to the location and name of the class) it&#8217;s very easy to figure out what classes you&#8217;re using.<br />
- Large codebases get confusing real fast if there is not a defined mapping of how to name files and classes.  If you&#8217;ve got two different &#8220;Account&#8221; classes and don&#8217;t have them either namespaced or class prefixed, you&#8217;re probably going to have problems anyway.<br />
- The stat call is something you&#8217;ve got to do explicitly in your autoloader if that&#8217;s the behavior you want.  It&#8217;s not required.  Zend Framework&#8217;s autoloader up until 1.8 didn&#8217;t use a stat call.  It just did a require on the code which meant 2 things&#8230;  First it was faster since it didn&#8217;t have a stat call, but second, if you were stacking autoloaders, the Zend loader would need to be done last since require will bomb if the file doesn&#8217;t exist.  The current version lets you configure this behavior.</p>
<p>Say perhaps you&#8217;re writing code using a strategy pattern.  The code to provide that strategy is determined at run-time.  If you go with the autoload way of doing things, only the classes and interfaces you need will be loaded.  If you go with require[_once], you&#8217;ll be including all the classes all the time, even if they aren&#8217;t needed.  That adds parsing and memory overhead.  If you go with include[_once] and only load the classes right before they are needed, you&#8217;ve no longer got the benefit of having all the classes you&#8217;re using in one place (typically the top of the file), and if it&#8217;s critical those files be loaded, include[_once] isn&#8217;t going to bail if there was a problem loading.</p>
<p>- Lastly, who says lazy cannot be right?  I think the benefits of using autoloader(s) greatly outweigh the downsides.  The benefits are there both for the developer (not having to jump up to the top to include a new class for another file), the performance (only including files that are requested, even if the code may have references to other classes on non-executed lines).  Additionally, as Brandon mentioned, new classes don&#8217;t need to be registered somewhere.  If you have any code that dynamically generates classes that may or may not actually exist, this can be a huge benefit.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: iflyhigh</title>
		<link>http://www.brandonsavage.net/making-life-better-with-the-spl-autoloader/#comment-787</link>
		<dc:creator>iflyhigh</dc:creator>
		<pubDate>Fri, 31 Jul 2009 10:04:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=492#comment-787</guid>
		<description>Autoloading is dumb.  Here&#039;s why:

- It makes your code WAY less clear.  Explicit imports document the classes your code relies on.  
- Large code bases become real confusing real fast.  
- It&#039;s slow.  stat()  Not there?  stat()  Not in this other place?  stat()  Not over here?  stat()  Oh, here it is?
- It&#039;s lazy, not &quot;right&quot;.</description>
		<content:encoded><![CDATA[<p>Autoloading is dumb.  Here&#8217;s why:</p>
<p>- It makes your code WAY less clear.  Explicit imports document the classes your code relies on.<br />
- Large code bases become real confusing real fast.<br />
- It&#8217;s slow.  stat()  Not there?  stat()  Not in this other place?  stat()  Not over here?  stat()  Oh, here it is?<br />
- It&#8217;s lazy, not &#8220;right&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brandon Savage</title>
		<link>http://www.brandonsavage.net/making-life-better-with-the-spl-autoloader/#comment-725</link>
		<dc:creator>Brandon Savage</dc:creator>
		<pubDate>Fri, 24 Jul 2009 20:16:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=492#comment-725</guid>
		<description>@passerby Because it&#039;s my blog. And simply put, I don&#039;t feel a need to regurgitate the manual. I provided an example and that was sufficient.</description>
		<content:encoded><![CDATA[<p>@passerby Because it&#8217;s my blog. And simply put, I don&#8217;t feel a need to regurgitate the manual. I provided an example and that was sufficient.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: passerby</title>
		<link>http://www.brandonsavage.net/making-life-better-with-the-spl-autoloader/#comment-723</link>
		<dc:creator>passerby</dc:creator>
		<pubDate>Fri, 24 Jul 2009 19:48:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=492#comment-723</guid>
		<description>Thanks for the explanation Herman.</description>
		<content:encoded><![CDATA[<p>Thanks for the explanation Herman.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: passerby</title>
		<link>http://www.brandonsavage.net/making-life-better-with-the-spl-autoloader/#comment-722</link>
		<dc:creator>passerby</dc:creator>
		<pubDate>Fri, 24 Jul 2009 19:47:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=492#comment-722</guid>
		<description>If you don&#039;t want to go into that depth why didn&#039;t you just talk about __autoload() instead?</description>
		<content:encoded><![CDATA[<p>If you don&#8217;t want to go into that depth why didn&#8217;t you just talk about __autoload() instead?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brandon Savage</title>
		<link>http://www.brandonsavage.net/making-life-better-with-the-spl-autoloader/#comment-720</link>
		<dc:creator>Brandon Savage</dc:creator>
		<pubDate>Fri, 24 Jul 2009 14:43:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=492#comment-720</guid>
		<description>That&#039;s a very good point, Herman. I didn&#039;t want to go into that sort of depth (it&#039;s a brief introduction) but you are 100% right. And that&#039;s the real beauty - PHP will do the work. It makes life easy when you integrate multiple frameworks together, like I do, to be able to let each of them define their own autoload function.</description>
		<content:encoded><![CDATA[<p>That&#8217;s a very good point, Herman. I didn&#8217;t want to go into that sort of depth (it&#8217;s a brief introduction) but you are 100% right. And that&#8217;s the real beauty &#8211; PHP will do the work. It makes life easy when you integrate multiple frameworks together, like I do, to be able to let each of them define their own autoload function.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Herman Radtke</title>
		<link>http://www.brandonsavage.net/making-life-better-with-the-spl-autoloader/#comment-719</link>
		<dc:creator>Herman Radtke</dc:creator>
		<pubDate>Fri, 24 Jul 2009 14:39:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=492#comment-719</guid>
		<description>The real beauty of spl_autoload_register() is that it is a stack.  That means I can register multiple __autoload functions and let PHP do the hard work.

Example:
spl_autoload_register(&#039;library_autoloader&#039;);
spl_autoload_register(&#039;app_autoloader&#039;);
spl_autoload_register(&#039;3rdparty_autoloader&#039;);


$calc = new App_Calc; // the library_autoloader() is tried first and fails.  the app_autoloader() is tried second and succeeds.</description>
		<content:encoded><![CDATA[<p>The real beauty of spl_autoload_register() is that it is a stack.  That means I can register multiple __autoload functions and let PHP do the hard work.</p>
<p>Example:<br />
spl_autoload_register(&#8216;library_autoloader&#8217;);<br />
spl_autoload_register(&#8216;app_autoloader&#8217;);<br />
spl_autoload_register(&#8217;3rdparty_autoloader&#8217;);</p>
<p>$calc = new App_Calc; // the library_autoloader() is tried first and fails.  the app_autoloader() is tried second and succeeds.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SchizoDuckie</title>
		<link>http://www.brandonsavage.net/making-life-better-with-the-spl-autoloader/#comment-716</link>
		<dc:creator>SchizoDuckie</dc:creator>
		<pubDate>Fri, 24 Jul 2009 12:57:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=492#comment-716</guid>
		<description>@brandon 

I see now, really handy to register classes that have multiple dependencies, nice :-)</description>
		<content:encoded><![CDATA[<p>@brandon </p>
<p>I see now, really handy to register classes that have multiple dependencies, nice :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brandon Savage</title>
		<link>http://www.brandonsavage.net/making-life-better-with-the-spl-autoloader/#comment-715</link>
		<dc:creator>Brandon Savage</dc:creator>
		<pubDate>Fri, 24 Jul 2009 12:55:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=492#comment-715</guid>
		<description>@mihailt - I&#039;ve typically found sometimes it&#039;s better to do it &quot;right&quot; than &quot;efficiently&quot; since boxes are inexpensive. However, you are right, that sometimes it can be slow.

@SchizoDuckie spl_autoload_register lets you register a callback which can then be used multiple times without having to individually register the classes. This means that when you add new classes, new registration isn&#039;t required.</description>
		<content:encoded><![CDATA[<p>@mihailt &#8211; I&#8217;ve typically found sometimes it&#8217;s better to do it &#8220;right&#8221; than &#8220;efficiently&#8221; since boxes are inexpensive. However, you are right, that sometimes it can be slow.</p>
<p>@SchizoDuckie spl_autoload_register lets you register a callback which can then be used multiple times without having to individually register the classes. This means that when you add new classes, new registration isn&#8217;t required.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SchizoDuckie</title>
		<link>http://www.brandonsavage.net/making-life-better-with-the-spl-autoloader/#comment-712</link>
		<dc:creator>SchizoDuckie</dc:creator>
		<pubDate>Fri, 24 Jul 2009 10:22:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=492#comment-712</guid>
		<description>What&#039;s the difference between this and __autoload() ? I noticed that you can register more than one __autoload or so ? (whatever the use of that is)</description>
		<content:encoded><![CDATA[<p>What&#8217;s the difference between this and __autoload() ? I noticed that you can register more than one __autoload or so ? (whatever the use of that is)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jan!</title>
		<link>http://www.brandonsavage.net/making-life-better-with-the-spl-autoloader/#comment-711</link>
		<dc:creator>Jan!</dc:creator>
		<pubDate>Fri, 24 Jul 2009 09:11:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=492#comment-711</guid>
		<description>In PHP 5.3, use a directory structure that matches the namespace scheme. Then, all you need to do, is include the class name after replacing &#039;\&#039; with \DIRECTORY_SEPARATOR (and appending &#039;.php&#039;, or whatnot).</description>
		<content:encoded><![CDATA[<p>In PHP 5.3, use a directory structure that matches the namespace scheme. Then, all you need to do, is include the class name after replacing &#8216;\&#8217; with \DIRECTORY_SEPARATOR (and appending &#8216;.php&#8217;, or whatnot).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Botnary</title>
		<link>http://www.brandonsavage.net/making-life-better-with-the-spl-autoloader/#comment-709</link>
		<dc:creator>Botnary</dc:creator>
		<pubDate>Fri, 24 Jul 2009 08:31:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=492#comment-709</guid>
		<description>thanks :) great tool and good idea to load classes..</description>
		<content:encoded><![CDATA[<p>thanks :) great tool and good idea to load classes..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mihailt</title>
		<link>http://www.brandonsavage.net/making-life-better-with-the-spl-autoloader/#comment-708</link>
		<dc:creator>mihailt</dc:creator>
		<pubDate>Fri, 24 Jul 2009 08:08:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=492#comment-708</guid>
		<description>the feature is nice yes, but from my experience if you use this solution in highload environment that it can dramatically reduce performance, but in most other areas that can make a great deal.</description>
		<content:encoded><![CDATA[<p>the feature is nice yes, but from my experience if you use this solution in highload environment that it can dramatically reduce performance, but in most other areas that can make a great deal.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk (feed is rejected)
Page Caching using apc (user agent is rejected)
Database Caching 44/51 queries in 0.010 seconds using disk
Content Delivery Network via Amazon Web Services: S3: files.brandonsavage.net.s3.amazonaws.com

Served from: www.brandonsavage.net @ 2010-07-31 11:15:19 -->