<?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"
	>
<channel>
	<title>Comments on: What’s your plan for __autoload()?</title>
	<atom:link href="http://www.sitepoint.com/blogs/2005/11/23/whats-your-plan-for-autoload/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sitepoint.com/blogs/2005/11/23/whats-your-plan-for-autoload/</link>
	<description>News, opinion, and fresh thinking for web developers and designers. The official podcast of sitepoint.com.</description>
	<pubDate>Tue, 02 Dec 2008 01:34:58 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
		<item>
		<title>By: Kristian</title>
		<link>http://www.sitepoint.com/blogs/2005/11/23/whats-your-plan-for-autoload/#comment-151529</link>
		<dc:creator>Kristian</dc:creator>
		<pubDate>Thu, 11 Jan 2007 16:00:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1322#comment-151529</guid>
		<description>Nice work, I tested it online but am getting this weird error: Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/public_html/dev/includes/smartloader.class.php on line 299

any idea why?</description>
		<content:encoded><![CDATA[<p>Nice work, I tested it online but am getting this weird error: Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/public_html/dev/includes/smartloader.class.php on line 299</p>
<p>any idea why?</p>]]></content:encoded>
	</item>
	<item>
		<title>By: SitePoint Blogs &#187; SmartLoader Reloaded</title>
		<link>http://www.sitepoint.com/blogs/2005/11/23/whats-your-plan-for-autoload/#comment-17245</link>
		<dc:creator>SitePoint Blogs &#187; SmartLoader Reloaded</dc:creator>
		<pubDate>Fri, 07 Apr 2006 12:36:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1322#comment-17245</guid>
		<description>[...] A few months ago I proposed a way to efficiently use __autoload() together with a class indexer. To my surprise, quite some people started using it and provided me with bug reports. I rewrote most of the original code, eliminated all known bugs and have been testing it for the last month. So here&#8217;s a new version with some improvements: [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] A few months ago I proposed a way to efficiently use __autoload() together with a class indexer. To my surprise, quite some people started using it and provided me with bug reports. I rewrote most of the original code, eliminated all known bugs and have been testing it for the last month. So here&#8217;s a new version with some improvements: [&#8230;]</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Schmelzer </title>
		<link>http://www.sitepoint.com/blogs/2005/11/23/whats-your-plan-for-autoload/#comment-15485</link>
		<dc:creator>Robert Schmelzer </dc:creator>
		<pubDate>Sat, 11 Mar 2006 14:15:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1322#comment-15485</guid>
		<description>I just implemented your Smartloader into my project. Very fine stuff. Good work.

But I encountered a bug:

The preg_match_all statement did not work in my PHP 5.1.2 distribution. The result array was empty. So I had to change it to the following: 

if($buf = fread($php_file, filesize($file_path))) {			$result = array();
	if(preg_match_all("%(interface&#124;class)\s+(\w+)\s+(extends\s+(\w+)\s+)?(implements\s+\w+\s*(,\s*\w+\s*)*)?{%", $buf, $result)) {
			foreach($result[2] as $class_name) 
...</description>
		<content:encoded><![CDATA[<p>I just implemented your Smartloader into my project. Very fine stuff. Good work.</p>
<p>But I encountered a bug:</p>
<p>The preg_match_all statement did not work in my PHP 5.1.2 distribution. The result array was empty. So I had to change it to the following: </p>
<p>if($buf = fread($php_file, filesize($file_path))) {			$result = array();<br />
	if(preg_match_all(&#8221;%(interface|class)\s+(\w+)\s+(extends\s+(\w+)\s+)?(implements\s+\w+\s*(,\s*\w+\s*)*)?{%&#8221;, $buf, $result)) {<br />
			foreach($result[2] as $class_name)<br />
&#8230;</p>]]></content:encoded>
	</item>
	<item>
		<title>By: dasluq [at( gmail )d0t] com</title>
		<link>http://www.sitepoint.com/blogs/2005/11/23/whats-your-plan-for-autoload/#comment-12361</link>
		<dc:creator>dasluq [at( gmail )d0t] com</dc:creator>
		<pubDate>Fri, 30 Dec 2005 10:25:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1322#comment-12361</guid>
		<description>another small bug:

SmartLoader fails with an error if the class was not found. However, it may have been called through &lt;code&gt;class_exists()&lt;/code&gt;, in which case a non-existent class name is perfectly OK as an argument.

IMHO the trigger_error is not necessary, so I just stripped it, replacing
&lt;code&gt;
		if(!$ldr-&#62;loadClass($class_name)) {
			trigger_error("SmartLoader: Cannot load class '".$class_name."'", E_USER_ERROR);
		}
&lt;/code&gt;

by

&lt;code&gt;
return $ldr-&#62;loadClass($class_name);
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>another small bug:</p>
<p>SmartLoader fails with an error if the class was not found. However, it may have been called through <code>class_exists()</code>, in which case a non-existent class name is perfectly OK as an argument.</p>
<p>IMHO the trigger_error is not necessary, so I just stripped it, replacing<br />
<code>
		if(!$ldr-&gt;loadClass($class_name)) {
			trigger_error("SmartLoader: Cannot load class '".$class_name."'", E_USER_ERROR);
		}
</code></p>
<p>by</p>
<code>
return $ldr-&gt;loadClass($class_name);
</code>]]></content:encoded>
	</item>
	<item>
		<title>By: SuperBetaTester</title>
		<link>http://www.sitepoint.com/blogs/2005/11/23/whats-your-plan-for-autoload/#comment-12063</link>
		<dc:creator>SuperBetaTester</dc:creator>
		<pubDate>Fri, 16 Dec 2005 18:16:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1322#comment-12063</guid>
		<description>Little bug:
SmartLoader do not caches classes when the bracket is tied to the classname:
&lt;code&gt;class ClassName2 extends ClassName2{&lt;/code&gt;
ClassName2 won't be cached. Some libraries use this ('bad') coding standard.</description>
		<content:encoded><![CDATA[<p>Little bug:<br />
SmartLoader do not caches classes when the bracket is tied to the classname:<br />
<code>class ClassName2 extends ClassName2{</code><br />
ClassName2 won&#8217;t be cached. Some libraries use this (&#8217;bad&#8217;) coding standard.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: coffee_ninja</title>
		<link>http://www.sitepoint.com/blogs/2005/11/23/whats-your-plan-for-autoload/#comment-11245</link>
		<dc:creator>coffee_ninja</dc:creator>
		<pubDate>Mon, 28 Nov 2005 16:46:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1322#comment-11245</guid>
		<description>&#60;devils_advocate&#62;

Harry had stated toward the beginning of this thread that
&lt;blockquote&gt;...calls to require_once, even when a file has been included, can get expensive and it looks like this approach would really help reduce that.&lt;/blockquote&gt;

But how much cheaper is a call to &lt;em&gt;__autoload()&lt;/em&gt; that searches the directory structures in the include path for some generic file name?  Aren't you essentially mimicking the functionality that &lt;em&gt;require&lt;/em&gt;, &lt;em&gt;require_once&lt;/em&gt;, &lt;em&gt;include&lt;/em&gt; and &lt;em&gt;include_once&lt;/em&gt; already provide (that is, searching the include path for the desired file)? It would be interesting to test and compare these two methods.

I worry that many programmers are going to use __autoload() as a wrapper to require_once() and add accomplish nothing but add complexity to their applications.  The only time I can see a benefit to using __autoload() is in the event that an object must be instantiated whose class isn't known until runtime.  And even then you'd need to be extremely careful for the security reasons mentioned above.

&#60;/devils_advocate&#62;</description>
		<content:encoded><![CDATA[<p>&lt;devils_advocate&gt;</p>
<p>Harry had stated toward the beginning of this thread that</p>
<blockquote><p>&#8230;calls to require_once, even when a file has been included, can get expensive and it looks like this approach would really help reduce that.</p></blockquote>
<p>But how much cheaper is a call to <em>__autoload()</em> that searches the directory structures in the include path for some generic file name?  Aren&#8217;t you essentially mimicking the functionality that <em>require</em>, <em>require_once</em>, <em>include</em> and <em>include_once</em> already provide (that is, searching the include path for the desired file)? It would be interesting to test and compare these two methods.</p>
<p>I worry that many programmers are going to use __autoload() as a wrapper to require_once() and add accomplish nothing but add complexity to their applications.  The only time I can see a benefit to using __autoload() is in the event that an object must be instantiated whose class isn&#8217;t known until runtime.  And even then you&#8217;d need to be extremely careful for the security reasons mentioned above.</p>
<p>&lt;/devils_advocate&gt;</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Etnu</title>
		<link>http://www.sitepoint.com/blogs/2005/11/23/whats-your-plan-for-autoload/#comment-11190</link>
		<dc:creator>Etnu</dc:creator>
		<pubDate>Fri, 25 Nov 2005 20:32:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1322#comment-11190</guid>
		<description>I find __autoload invaluable, because it allows for a great deal of flexibility when it comes to moving libraries around, as well as helping reduce the clutter of all the include statements.

I usually tweak autoload just slightly to do the following:

&lt;pre&gt;&lt;code class="php"&gt;
GLOBAL_LIB_DIR.'Classes/Class1.php',
'Class2'=&#62;GLOBAL_LIB_DIR.'Classes/Class2.php',
'Interface1'=&#62;GLOBAL_LIB_DIR.'Interfaces/Interface1.php',
);
&lt;/code&gt;&lt;/pre&gt;

and so on and so forth.

This allows me to easily define where any given class / set of classes will reside. I generally try to keep everything in a common lib folder, but within that you'll still want to break down into subfolders for different "packages".</description>
		<content:encoded><![CDATA[<p>I find __autoload invaluable, because it allows for a great deal of flexibility when it comes to moving libraries around, as well as helping reduce the clutter of all the include statements.</p>
<p>I usually tweak autoload just slightly to do the following:</p>
<pre><code class="php">
GLOBAL_LIB_DIR.'Classes/Class1.php',
'Class2'=&gt;GLOBAL_LIB_DIR.'Classes/Class2.php',
'Interface1'=&gt;GLOBAL_LIB_DIR.'Interfaces/Interface1.php',
);
</code></pre>
<p>and so on and so forth.</p>
<p>This allows me to easily define where any given class / set of classes will reside. I generally try to keep everything in a common lib folder, but within that you&#8217;ll still want to break down into subfolders for different &#8220;packages&#8221;.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://www.sitepoint.com/blogs/2005/11/23/whats-your-plan-for-autoload/#comment-11176</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Fri, 25 Nov 2005 05:56:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1322#comment-11176</guid>
		<description>It isnt. 

But you don't need the require statements if you use this method. A useful thing when you have a large app/site with loads of classes.</description>
		<content:encoded><![CDATA[<p>It isnt. </p>
<p>But you don&#8217;t need the require statements if you use this method. A useful thing when you have a large app/site with loads of classes.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Heimi</title>
		<link>http://www.sitepoint.com/blogs/2005/11/23/whats-your-plan-for-autoload/#comment-11173</link>
		<dc:creator>Heimi</dc:creator>
		<pubDate>Fri, 25 Nov 2005 04:03:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1322#comment-11173</guid>
		<description>Forgive me if this sounds stupid, but how is this any different from doing

&lt;code&gt;
// Stuff...
require_once 'thing1.php';
$thing1 = new Thing1();
// More Stuff...
require_once 'thing2.php;
$thing2 = new Thing2();
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Forgive me if this sounds stupid, but how is this any different from doing</p>
<code>
// Stuff...
require_once 'thing1.php';
$thing1 = new Thing1();
// More Stuff...
require_once 'thing2.php;
$thing2 = new Thing2();
</code>]]></content:encoded>
	</item>
	<item>
		<title>By: mrsmiley</title>
		<link>http://www.sitepoint.com/blogs/2005/11/23/whats-your-plan-for-autoload/#comment-11169</link>
		<dc:creator>mrsmiley</dc:creator>
		<pubDate>Thu, 24 Nov 2005 21:31:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1322#comment-11169</guid>
		<description>The problem is and always has been the performance of the stat lookups the engine does when trying to detirmine if a file is there or not.  I heard a while ago that there was supposed to be a better file stat cache built into the zend engine to try and combat this problem, but I would guess that such a cache is only really useful (depending on how its implemented) when run in a sapi/module environment as opposed to cgi.  Having a pre-parsed mapping of class name to file location is the ideal method as it performs the best.  Couple that with the appropriate validation, and it should be an excellent solution.</description>
		<content:encoded><![CDATA[<p>The problem is and always has been the performance of the stat lookups the engine does when trying to detirmine if a file is there or not.  I heard a while ago that there was supposed to be a better file stat cache built into the zend engine to try and combat this problem, but I would guess that such a cache is only really useful (depending on how its implemented) when run in a sapi/module environment as opposed to cgi.  Having a pre-parsed mapping of class name to file location is the ideal method as it performs the best.  Couple that with the appropriate validation, and it should be an excellent solution.</p>]]></content:encoded>
	</item>
</channel>
</rss>
