<?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>Oliver Nassar &#187; PHP5</title>
	<atom:link href="http://www.olivernassar.com/tag/php5/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.olivernassar.com</link>
	<description>Making the interwebs.</description>
	<lastBuildDate>Thu, 12 Nov 2009 22:17:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP: Abstract classes vs static classes; whats what?</title>
		<link>http://www.olivernassar.com/2009/10/07/php-abstract-classes-vs-static-classes-whats-what/</link>
		<comments>http://www.olivernassar.com/2009/10/07/php-abstract-classes-vs-static-classes-whats-what/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 20:48:48 +0000</pubDate>
		<dc:creator>onassar</dc:creator>
				<category><![CDATA[PHP5]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[abstract]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[oo]]></category>
		<category><![CDATA[static]]></category>

		<guid isPermaLink="false">http://www.olivernassar.com/?p=253</guid>
		<description><![CDATA[<a href="http://www.olivernassar.com/2009/10/07/php-abstract-classes-vs-static-classes-whats-what/" rel="attachment wp-att-255"><img src="http://www.olivernassar.com/wp-content/uploads/2009/10/tv_static_2-150x150.jpg" alt="tv_static_2" title="tv_static_2" width="150" height="150" class="alignleft size-thumbnail wp-image-255" /></a>In the past I've spent a great deal of time trying to understand the different between PHP5 abstract and static classes/methods. I find out, use the differences on whatever I'm doing, and the forget. No more. I will document my understanding here to help myself, and some day others, out.

Methods (not classes) can be defined as static (eg. not static class Oliver{} but rather static function talk()) in order to call them without going through an instantiated object. From my perspective, it makes code cleaner and less messy by wrapping related functions in a class wrapper instead of defining them globally. It should be noted though, that classes with static methods CAN be instantiated, and those methods can be called either statically (via the :: double colon notation, or via the -> right arrow notation on the instantiated object).]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.olivernassar.com/wp-content/uploads/2009/10/tv_static_2-150x150.jpg" alt="tv_static_2" title="tv_static_2" width="150" height="150" class="alignleft size-thumbnail wp-image-255" />In the past I&#8217;ve spent a great deal of time trying to understand the different between PHP5 abstract and static classes/methods. I find out, use the differences on whatever I&#8217;m doing, and the forget. No more. I will document my understanding here to help myself, and some day others, out.</p>
<p>Methods (not classes) can be defined as static (eg. not static class Oliver{} but rather static function talk()) in order to call them without going through an instantiated object. From my perspective, it makes code cleaner and less messy by wrapping related functions in a class wrapper instead of defining them globally. It should be noted though, that classes with static methods CAN be instantiated, and those methods can be called either statically (via the :: double colon notation, or via the -> right arrow notation on the instantiated object).</p>
<p>That takes us to abstract classes. Abstract classes CANNOT be instantiated. They can be the parent of a class which can be instantiated, but they themselves cannot be. So for example, if I have two types of users, RegularUser and AdminUser, I could create an abstract class User which defines method signatures (via the abstract keyword) like abstract function login($username,$password){} or I can define static functions which can be called (via the same rules as above). A new User object can never be created directly though.</p>
<p>So what does that mean in terms of real-world usage? Personally, if I don&#8217;t want a class every to be instantiated, such as a class that has utility functions or string manipulation functions, I will define it as abstract, and define all it&#8217;s methods to be static. If I have a parent object which should never be instantiated, I&#8217;ll do the same, but leave the method declarations to the child classes for the most part.</p>
<p>So then when do I use a normal class that happens to have static methods? I haven&#8217;t really. I&#8217;m sure there can be uses for it, but I&#8217;ve never found myself in a situation where I need to access an object&#8217;s method without the context of the object&#8217;s instantiation. Maybe it&#8217;ll come up one day, but as I&#8217;m moving closer and closer to a full mvc based coding life style, I have a feeling that I won&#8217;t find myself in that situation anytime soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.olivernassar.com/2009/10/07/php-abstract-classes-vs-static-classes-whats-what/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Reflection class: a gem I found</title>
		<link>http://www.olivernassar.com/2009/08/09/php-reflection-class-a-gem-i-found/</link>
		<comments>http://www.olivernassar.com/2009/08/09/php-reflection-class-a-gem-i-found/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 18:29:52 +0000</pubDate>
		<dc:creator>onassar</dc:creator>
				<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[PHP5]]></category>
		<category><![CDATA[error handling]]></category>
		<category><![CDATA[parameters]]></category>
		<category><![CDATA[reflection]]></category>

		<guid isPermaLink="false">http://www.olivernassar.com/?p=150</guid>
		<description><![CDATA[<a href="http://www.olivernassar.com/2009/08/09/php-reflection-class-a-gem-i-found/" rel="attachment wp-att-151"><img src="http://www.olivernassar.com/wp-content/uploads/2009/08/eagle-reflection_6646-150x150.jpg" alt="Narcissistic Eagle" title="Narcissistic Eagle" width="150" height="150" class="alignleft size-thumbnail wp-image-151" />In developing my own mash-up of a framework, drawing inspiration from a lot of different areas, I ran into an interesting hurdles.

Since my framework is MVC based, I ran into a problem whereby calling an action/method in a controller should only be fulfilled if the number of parameters passed in was valid. So for example, if I was dealing with a user's model, and I wanted to return the email address for the user, I would normally access it via a url pattern such as: http://www.website.com/users/details/email/]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.olivernassar.com/wp-content/uploads/2009/08/eagle-reflection_6646-150x150.jpg" alt="Narcissistic Eagle" title="Narcissistic Eagle" width="150" height="150" class="alignleft size-thumbnail wp-image-151" />In developing my own mash-up of a framework, drawing inspiration from a lot of different areas, I ran into an interesting hurdles.</p>
<p>Since my framework is MVC based, I ran into a problem whereby calling an action/method in a controller should only be fulfilled if the number of parameters passed in was valid. So for example, if I was dealing with a user&#8217;s model, and I wanted to return the email address for the user, I would normally access it via a url pattern such as: http://www.website.com/users/details/email/</p>
<p>On the server side, this would access the Users controller, the details method, and pass in a parameter with the value &#8216;email&#8217;. The method would then grab it from the db, and return it however it decided. The trick came in, however, as to validating the parameters that were passed to a controller&#8217;s action/method. So for example, http://www.website.com/users/details/email/oliver/ would pass the details method/action two parameters with values &#8216;email&#8217;, and &#8216;oliver&#8217;.</p>
<p>But my method/action only accepts one. So what should happen? Well ideally, a 404/error page should be pushed out, but how would PHP know that the parameter count doesn&#8217;t match? You have two options. One is very intrusive, and the other is best thing ever.</p>
<p>1) Intrusive: in every action, hard code something like:<br />
<code>if(func_num_args()>HARDCODED_NUMBER)<br />
    // redirect<br />
</code>This would mean every action/method would need to do this check to make sure the right number of param&#8217;s were sent in (this doesn&#8217;t even take into account the minimum number of req&#8217;d parameters; only the max allowed.</p>
<p>2) The best way ever: before making a call to controller&#8217;s action use the <a href="http://nz.php.net/oop5.reflection">Reflection class</a>.<br />
This class allows you to check the parameter requirements of a call BEFORE you actually make it. So using php5&#8217;s Reflection class, you can check to see how many parameters are required at a minimum (excludes required praams&#8217;), how many are the max, and even more fun stuff. This allows you to centralize the error handling for controller calls to the dispatcher (my naming convention for the class/method that actually makes the calls to an action/method), keep your code very clean and clear.</p>
<p>I did some checking, and it seems using this class isn&#8217;t too expensive since this information is contained by php be default; it&#8217;s just that this extension contains the API for actually accessing it.</p>
<p>It&#8217;s a win-win situation as far as I&#8217;m concerned.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.olivernassar.com/2009/08/09/php-reflection-class-a-gem-i-found/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Framework: S^3 (aka S cubed): I&#8217;m calling it Smart Setting Selection</title>
		<link>http://www.olivernassar.com/2009/08/03/framework-s3-aka-s-cubed-im-calling-it-smart-setting-selection/</link>
		<comments>http://www.olivernassar.com/2009/08/03/framework-s3-aka-s-cubed-im-calling-it-smart-setting-selection/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 23:32:22 +0000</pubDate>
		<dc:creator>onassar</dc:creator>
				<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[PHP5]]></category>
		<category><![CDATA[ini]]></category>
		<category><![CDATA[settings]]></category>

		<guid isPermaLink="false">http://www.olivernassar.com/?p=129</guid>
		<description><![CDATA[<a href="http://www.olivernassar.com/2009/08/03/framework-s3-aka-s-cubed-im-calling-it-smart-setting-selection/" rel="attachment wp-att-130"><img src="http://www.olivernassar.com/wp-content/uploads/2009/08/558px-Selection.svg-150x150.png" alt="558px-Selection.svg" title="558px-Selection.svg" width="150" height="150" class="alignleft size-thumbnail wp-image-130" /></a>In working on a custom framework (that's uniting a lot of the best of the existing ones, but keeping it lean and cutting out what I don't need), I ran into a configuration roadblock which caused me to write some nifty code.

Basically, this framework has a bunch of settings/config files, and some of the files (ini format, using parse_ini_file) are seperated by the following keywords:
local,development,staging,production]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.olivernassar.com/wp-content/uploads/2009/08/558px-Selection.svg-150x150.png" alt="558px-Selection.svg" title="558px-Selection.svg" width="150" height="150" class="alignleft size-thumbnail wp-image-130" />In working on a custom framework (that&#8217;s uniting a lot of the best of the existing ones, but keeping it lean and cutting out what I don&#8217;t need), I ran into a configuration roadblock which caused me to write some nifty code.</p>
<p>Basically, this framework has a bunch of settings/config files, and some of the files (ini format, using parse_ini_file) are seperated by the following keywords:<br />
local,development,staging,production</p>
<p>Basically meaning, if I have a configuration setting that is supposed to mean something like &#8216;maxTimeout = 500&#8242;, I could, and in a real world application, would have that setting store different values based on which server the code base is being run on (eg. my local would be a lot higher, but the other ones like the production would be much lower for optimization purposes).</p>
<p>This lead me to write some nifty code that will parse all the ini files, and then when I want to retrieve something, it does a check for one of those 4 reserved words. So a real world example would be something like this:</p>
<p>An ini file is parsed and has the following format:<br />
<code><br />
Array<br />
(<br />
    [local] => Array<br />
                    (<br />
                        [name] => TEST<br />
                        [cookies] => 1<br />
                    )<br />
    [production] => Array<br />
                               (<br />
                                   [name] => TEST<br />
                                   [cookies] => 1<br />
                               )<br />
)<br />
</code></p>
<p>When doing a call to the function and asking for the setting &#8216;name&#8217;, recursively as it moves it&#8217;s way down the settings array, it&#8217;ll look to see if it contains a keyword of local, production, etc., and if it does, automatically set the value to that array/value. This will be clearer once I OS the framework which won&#8217;t be for a while, but to understand it from a code perspective, check this out:</p>
<p><code><br />
        public static function getDetails() {<br />
            $details    =    self::$details;<br />
            foreach(func_get_args() as $argument) {<br />
                $details    =    $details[$argument];<br />
                if(array_key_exists(Request::getServerRole(),(array) $details))<br />
                    $details    =    $details[Request::getServerRole()];<br />
            }<br />
            return $details;<br />
        }<br />
</code></p>
<p>This means that my server will automatically pull the right setting detail based on what server is doing the requesting. I just need to setup my ini files so that if a setting needs to be different based on which server is being loaded, it can be.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.olivernassar.com/2009/08/03/framework-s3-aka-s-cubed-im-calling-it-smart-setting-selection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What framework does php.net use? Answer: I don&#8217;t know.</title>
		<link>http://www.olivernassar.com/2009/07/22/what-framework-does-php-net-use-answer-i-dont-know/</link>
		<comments>http://www.olivernassar.com/2009/07/22/what-framework-does-php-net-use-answer-i-dont-know/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 19:38:26 +0000</pubDate>
		<dc:creator>onassar</dc:creator>
				<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[PHP5]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[lerdorf]]></category>
		<category><![CDATA[php.net]]></category>
		<category><![CDATA[rasumus]]></category>

		<guid isPermaLink="false">http://www.olivernassar.com/?p=46</guid>
		<description><![CDATA[<img class="alignleft size-thumbnail wp-image-50" src="http://www.olivernassar.com/wp-content/uploads/2009/07/mario-wedding-cake-150x150.jpg" alt="mario-wedding-cake" width="150" height="150" />I've been looking at frameworks a lot lately. Mainly for an upcoming project, but also to getting a better understanding of MVC based development, as well as components/helpers for web development. That made be ask the question, what framework does php.net use for it's documentation/downloads site?]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-thumbnail wp-image-50" title="mario-wedding-cake" src="http://www.olivernassar.com/wp-content/uploads/2009/07/mario-wedding-cake-150x150.jpg" alt="mario-wedding-cake" width="150" height="150" /></p>
<p>I&#8217;ve been looking at frameworks a lot lately. Mainly for an upcoming project, but also to getting a better understanding of MVC based development, as well as components/helpers for web develop</p>
<p>ment. That made be ask the question, what framework does php.net use for it&#8217;s documentation/downloads site?</p>
<p>I read somewhere that Rasmus Lerdorf, the guy who invented php, who went to University of Waterloo, by the way, felt particularly fond of Code Igniter. I&#8217;ve looked at it, and heard great things mainly due to it&#8217;s ease of use, but echoing Rasmus&#8217; thoughts, if feels much more like a library than a framework, at least to me.</p>
<p>That&#8217;s not a bad thing; Rasmus&#8217; meant that positively. I personally don&#8217;t think you should be relying on an open source distribution to do the thinking for you. I&#8217;ve run into many people who claim to know javascript, but what they really mean is, is that they know how to use a framework like MooTools, JQuery, or YUI. Knowing JavaScript takes much more time, and takes a higher discipline. It&#8217;s not for everyone, but it&#8217;s not different than someone knowing how to use Dreamweaver or Frontpage, and advertising that they know how to develop website. You don&#8217;t know how to develop website, you know how to use a program that writes the sites for you, much like if you&#8217;re using a framework, you know how to use an open source distribution to help you write a website.</p>
<p>I&#8217;ve been playing a lot with CakePHP lately, and that, in my mind, is a true framework. Everything is native to Cake. Their site is very intimidating, and their framework is VERY expansive, but it&#8217;s therefore very powerful. I&#8217;m not sure it&#8217;s exactly what I was looking for, but it&#8217;s given me invaluable insight into framework development for php.</p>
<p>This then leads me back to the question of what php.net uses. My guess is a custom framework; not symfony, or cake, or CI, or zend or any of those guys (probably because they came about way later than php.net), but I&#8217;d be interested to know what they do use, and if they&#8217;d open source it. For now, I&#8217;ll keep working on my own framework that is geared towards being lean, and requiring me to do a lot of the heavy lifting for maximum flexibility. Hopefully I&#8217;ll open source it someday, and it&#8217;ll be able to meet the needs of people like me for whom Cake was too much, and CI (Code Igniter) was too little.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.olivernassar.com/2009/07/22/what-framework-does-php-net-use-answer-i-dont-know/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
