<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>westworld: a webmasters best friend &#187; autoload exception</title>
	<atom:link href="http://www.westworld.be/tag/autoload-exception/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.westworld.be</link>
	<description>A webmasters best friend</description>
	<lastBuildDate>Tue, 17 Aug 2010 10:37:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>__autoload function</title>
		<link>http://www.westworld.be/a-note-to-self/__autoload-function/</link>
		<comments>http://www.westworld.be/a-note-to-self/__autoload-function/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 08:05:07 +0000</pubDate>
		<dc:creator>westworld</dc:creator>
				<category><![CDATA[a note to self]]></category>
		<category><![CDATA[autoload exception]]></category>

		<guid isPermaLink="false">http://www.westworld.be/?p=108</guid>
		<description><![CDATA[Some info,snippets on PHP5 autoload function: function __autoload($className) { include_once __autoloadFilename($className); } function __autoloadFilename($className) { return str_replace('_','/',$className).".php"; } $class = new myclass(); When a Class is not found, php will pass the classname to the __autoload function. You can name your class like Folder1_Folder1a_Myclass and this function will look for it in Folder1/Folder1a/Myclass.php You can [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>Some info,snippets on PHP5 autoload function:</p>
<p><code>function __autoload($className) {<br />
include_once __autoloadFilename($className);<br />
}<br />
function __autoloadFilename($className) {<br />
return str_replace('_','/',$className).".php";<br />
}<br />
$class = new myclass();</code></p>
<p>When a Class is not found, php will pass the classname to the __autoload function.<br />
You can name your class like Folder1_Folder1a_Myclass and this function will look for it in Folder1/Folder1a/Myclass.php</p>
<p>You can put multiple classes in one folder and still make this work by creating a link to the correct file.<br />
On Unix, Linux machines use the command &#8220;ln -s targetfile.php nonexistingclassfile.php&#8221;</p>
<textarea cols="40" rows="10" name="code" class="Xml">Example using exception:(taken from php.net)
<?php
function __autoload($class)
{
    if (file_exists($file = "./inc/$class.php"))
    {include($file);}
    else{throw new Exception("Class $class not found");}
}

try{
    // Since the second argument defaults to true, __autoload()
    // will be called from this function
    class_exists('MyClass');
}
catch (Exception $e)
{
    // Catch the exception and handle it as usual
    die($e->getMessage());
}

// Safely initialize an object from the class
$class = new MyClass();
?></textarea>
	<!-- WordPress Code Snippet -->
	<script type="text/javascript" src="http://www.westworld.be/wp-content/plugins/wordpress-code-snippet/js/shCore.js"></script><script type="text/javascript" src="http://www.westworld.be/wp-content/plugins/wordpress-code-snippet/js/shBrushXml.js"></script>
	<link type="text/css" rel="stylesheet" href="http://www.westworld.be/wp-content/plugins/wordpress-code-snippet/css/SyntaxHighlighter.css"/>
	
	<script language="javascript">
	dp.SyntaxHighlighter.ClipboardSwf = 'http://www.westworld.be/wp-content/plugins/wordpress-code-snippet/js/clipboard.swf';
	dp.SyntaxHighlighter.HighlightAll('code');
	</script>
	<!-- End WordPress Code Snippet -->
	

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.westworld.be/a-note-to-self/__autoload-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
