<?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: Object-oriented PHP :: A guide for fellow ISys junkies</title>
	<atom:link href="http://aaronhardy.com/php/object-oriented-php-a-guide-for-fellow-isys-junkies/feed/" rel="self" type="application/rss+xml" />
	<link>http://aaronhardy.com/php/object-oriented-php-a-guide-for-fellow-isys-junkies/</link>
	<description>For all your Aaron Hardy needs.</description>
	<pubDate>Fri, 21 Nov 2008 21:14:09 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6-beta2</generator>
		<item>
		<title>By: Dave</title>
		<link>http://aaronhardy.com/php/object-oriented-php-a-guide-for-fellow-isys-junkies/#comment-28</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Sat, 24 May 2008 05:37:41 +0000</pubDate>
		<guid isPermaLink="false">http://intimateconversations.aaronhardy.com/uncategorized/object-oriented-php-a-guide-for-fellow-isys-junkies/#comment-28</guid>
		<description>Just wanted to tell you that you did a great job in laying out this PHP tutorial.
I've picked up quite a handful of good tips by reading it.
just wanted to let you know that somebody out there thought this was quite handy!
later</description>
		<content:encoded><![CDATA[<p>Just wanted to tell you that you did a great job in laying out this PHP tutorial.<br />
I&#8217;ve picked up quite a handful of good tips by reading it.<br />
just wanted to let you know that somebody out there thought this was quite handy!<br />
later</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Hardy</title>
		<link>http://aaronhardy.com/php/object-oriented-php-a-guide-for-fellow-isys-junkies/#comment-27</link>
		<dc:creator>Aaron Hardy</dc:creator>
		<pubDate>Fri, 10 Aug 2007 23:54:32 +0000</pubDate>
		<guid isPermaLink="false">http://intimateconversations.aaronhardy.com/uncategorized/object-oriented-php-a-guide-for-fellow-isys-junkies/#comment-27</guid>
		<description>Hey Andrew and Fernando!  I do appreciate you all joining...the intimate conversation!  Let's see what we can do here...

Andrew, when it comes to the difference between include() and require(), you can't get much better than what PHP's documentation has to say about it, so I'll just copy it in here:

"require() and include() are identical in every way except how they handle failure. They both produce a Warning, but require() results in a  Fatal Error. In other words, don't hesitate to use require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless."

Here's the reference: &lt;a href="http://www.php.net/require" target="_blank" rel="nofollow"&gt;Documentation on require()&lt;/a&gt;

Another thing to add to that is your server may react to warnings and fatal errors differently than another server, depending on your PHP configuration.  If you want to see how it works on your particular server, try this example (make sure test.php does NOT exist):


include("test.php");
echo "Am I still processing?";

Then try this one (again, test.php shouldn't exist):

include("test.php");
echo "Am I still processing?";
?&gt;

And, although you may have already figured it out, include_once() and require_once() check to see if the file was loaded before.  If it was, then it ignores the command and doesn't load the file again.  Personally, out of the four options (include(), include_once(), require(), and require_once()) I always choose require_once(). Hope that helps!

Fernando, thanks for the heads up!  I've made the corrections.  Three of them in fact.  After writing the article, I thought I'd be a little more creative than the usual HelloWorld, but apparently I let a few slip through the cracks.  Enjoy!</description>
		<content:encoded><![CDATA[<p>Hey Andrew and Fernando!  I do appreciate you all joining&#8230;the intimate conversation!  Let&#8217;s see what we can do here&#8230;</p>
<p>Andrew, when it comes to the difference between include() and require(), you can&#8217;t get much better than what PHP&#8217;s documentation has to say about it, so I&#8217;ll just copy it in here:</p>
<p>&#8220;require() and include() are identical in every way except how they handle failure. They both produce a Warning, but require() results in a  Fatal Error. In other words, don&#8217;t hesitate to use require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless.&#8221;</p>
<p>Here&#8217;s the reference: <a href="http://www.php.net/require" target="_blank" rel="nofollow">Documentation on require()</a></p>
<p>Another thing to add to that is your server may react to warnings and fatal errors differently than another server, depending on your PHP configuration.  If you want to see how it works on your particular server, try this example (make sure test.php does NOT exist):</p>
<p>include(&#8221;test.php&#8221;);<br />
echo &#8220;Am I still processing?&#8221;;</p>
<p>Then try this one (again, test.php shouldn&#8217;t exist):</p>
<p>include(&#8221;test.php&#8221;);<br />
echo &#8220;Am I still processing?&#8221;;<br />
?></p>
<p>And, although you may have already figured it out, include_once() and require_once() check to see if the file was loaded before.  If it was, then it ignores the command and doesn&#8217;t load the file again.  Personally, out of the four options (include(), include_once(), require(), and require_once()) I always choose require_once(). Hope that helps!</p>
<p>Fernando, thanks for the heads up!  I&#8217;ve made the corrections.  Three of them in fact.  After writing the article, I thought I&#8217;d be a little more creative than the usual HelloWorld, but apparently I let a few slip through the cracks.  Enjoy!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fernando Mladineo</title>
		<link>http://aaronhardy.com/php/object-oriented-php-a-guide-for-fellow-isys-junkies/#comment-26</link>
		<dc:creator>Fernando Mladineo</dc:creator>
		<pubDate>Fri, 10 Aug 2007 19:38:10 +0000</pubDate>
		<guid isPermaLink="false">http://intimateconversations.aaronhardy.com/uncategorized/object-oriented-php-a-guide-for-fellow-isys-junkies/#comment-26</guid>
		<description>Hey Aaron,

Just started reading your PHP tutorial and I'm already learning new things. I just wanted to point out that you made reference to sayHello() on page 2 instead of sayWoot(). Keep up the good work!</description>
		<content:encoded><![CDATA[<p>Hey Aaron,</p>
<p>Just started reading your PHP tutorial and I&#8217;m already learning new things. I just wanted to point out that you made reference to sayHello() on page 2 instead of sayWoot(). Keep up the good work!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew Hegerhorst</title>
		<link>http://aaronhardy.com/php/object-oriented-php-a-guide-for-fellow-isys-junkies/#comment-25</link>
		<dc:creator>Andrew Hegerhorst</dc:creator>
		<pubDate>Fri, 10 Aug 2007 00:54:20 +0000</pubDate>
		<guid isPermaLink="false">http://intimateconversations.aaronhardy.com/uncategorized/object-oriented-php-a-guide-for-fellow-isys-junkies/#comment-25</guid>
		<description>Way to go on the tutorial, Aaron. For us php noobs it's a keeper! I was reading through it and had a question, so I thought I would throw it out. Sadly, this will demonstrate exactly how new to php I am. ;)

Here's the question:

Do you have any thoughts as to when the require function should be used as opposed to the include function? I have read about it a little, but being new to php I would appreciate any thoughts you may have on the subject.

Again, great job on the tutorial...</description>
		<content:encoded><![CDATA[<p>Way to go on the tutorial, Aaron. For us php noobs it&#8217;s a keeper! I was reading through it and had a question, so I thought I would throw it out. Sadly, this will demonstrate exactly how new to php I am. <img src='http://aaronhardy.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
Here&#8217;s the question:</p>
<p>Do you have any thoughts as to when the require function should be used as opposed to the include function? I have read about it a little, but being new to php I would appreciate any thoughts you may have on the subject.</p>
<p>Again, great job on the tutorial&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Hardy</title>
		<link>http://aaronhardy.com/php/object-oriented-php-a-guide-for-fellow-isys-junkies/#comment-24</link>
		<dc:creator>Aaron Hardy</dc:creator>
		<pubDate>Thu, 09 Aug 2007 00:43:02 +0000</pubDate>
		<guid isPermaLink="false">http://intimateconversations.aaronhardy.com/uncategorized/object-oriented-php-a-guide-for-fellow-isys-junkies/#comment-24</guid>
		<description>Hey Scott!!  Thanks for joining...the intimate conversation.  I'm glad I could be of service, if only a little.  You've got some really good questions and I'm glad you posted them here publicly, because I'm not much of an authoritative source when it comes to the PHP core engine.  With that in mind, I'll do my best to provide insight where I can.

First off, I guess I completely forgot that we were using the singleton pattern for our DAOs during INTEX II!  In any case, I don't see much of an advantage to using the singleton pattern over static methods in this case.  I'd still choose the static methods over the singleton pattern, but I'd love to hear some rebuttal from someone as to why I shouldn't.

Okay, onto the stuff you were pondering.  I think most of your difficulties in finding what you're looking for is due to the difference in how PHP runs on the server compared to other frameworks like Java or .NET.  With Java, you wrote your code and then you had to manually (by clicking a button, likely) compile it before opening it up in a browser for the first time.  Then, you never had to re-compile your code until you had some code change that you wanted to take effect on the website.  On the other hand, PHP is different.  In the simplest of explanations, a PHP page is re-compiled each time it is called by a user.  That's why you don't have to hit any compile button in your IDE when you want to check out the new changes you've made.  There are some exceptions where you can actually compile PHP as a long-term executable or you can cache your pages, but again, my explanation is a simplistic one and I can't elaborate much on the exceptions.

Also, Java can be very thread-based whereas PHP...not so much.  Although there are web server environments that are threaded, PHP's support is fairly limited. In fact, you'll find a lot of articles where people say that the PHP development team recommends that you don't run PHP on Apache 2 in multi-threaded mode, but I have yet to see the original source of that statement.

So, taking the differences into consideration, there is no "synchronized" keyword in PHP because there are no threads to synchronize.  The same goes for using objects across all sessions.  One of the noted benefits of PHP is that everything in memory is cleaned up after each session.  There are no "application variables" (as they're called in ASP) where you can set up a variable that exists over multiple sessions.

This doesn't mean there aren't ways to implement functionality similar to what you're looking for though.  PHP has the session_set_save_handler() method that can help save a user's session to a database or file.  You can read about it here:

&lt;a href="http://www.php.net/session_set_save_handler" rel="nofollow"&gt;session_set_save_handler() documentation&lt;/a&gt;

Here's an implementation without using the session_set_save_handler() function:

&lt;a href="http://www.leosingleton.com/projects/code/phpapp/" rel="nofollow"&gt;Application variables in PHP&lt;/a&gt;

And if you're interested in hacking up some threading in PHP, here's an example:

&lt;a href="http://www.webforumz.com/php-forum/12595-multithreaded-php.htm" rel="nofollow"&gt;Multi-threaded PHP&lt;/a&gt;

Needless to say, none of these options are super-duper pretty, but that's not really PHP's niche.

Anyone else want to comment? Please, I invite you to join....the intimate conversation.</description>
		<content:encoded><![CDATA[<p>Hey Scott!!  Thanks for joining&#8230;the intimate conversation.  I&#8217;m glad I could be of service, if only a little.  You&#8217;ve got some really good questions and I&#8217;m glad you posted them here publicly, because I&#8217;m not much of an authoritative source when it comes to the PHP core engine.  With that in mind, I&#8217;ll do my best to provide insight where I can.</p>
<p>First off, I guess I completely forgot that we were using the singleton pattern for our DAOs during INTEX II!  In any case, I don&#8217;t see much of an advantage to using the singleton pattern over static methods in this case.  I&#8217;d still choose the static methods over the singleton pattern, but I&#8217;d love to hear some rebuttal from someone as to why I shouldn&#8217;t.</p>
<p>Okay, onto the stuff you were pondering.  I think most of your difficulties in finding what you&#8217;re looking for is due to the difference in how PHP runs on the server compared to other frameworks like Java or .NET.  With Java, you wrote your code and then you had to manually (by clicking a button, likely) compile it before opening it up in a browser for the first time.  Then, you never had to re-compile your code until you had some code change that you wanted to take effect on the website.  On the other hand, PHP is different.  In the simplest of explanations, a PHP page is re-compiled each time it is called by a user.  That&#8217;s why you don&#8217;t have to hit any compile button in your IDE when you want to check out the new changes you&#8217;ve made.  There are some exceptions where you can actually compile PHP as a long-term executable or you can cache your pages, but again, my explanation is a simplistic one and I can&#8217;t elaborate much on the exceptions.</p>
<p>Also, Java can be very thread-based whereas PHP&#8230;not so much.  Although there are web server environments that are threaded, PHP&#8217;s support is fairly limited. In fact, you&#8217;ll find a lot of articles where people say that the PHP development team recommends that you don&#8217;t run PHP on Apache 2 in multi-threaded mode, but I have yet to see the original source of that statement.</p>
<p>So, taking the differences into consideration, there is no &#8220;synchronized&#8221; keyword in PHP because there are no threads to synchronize.  The same goes for using objects across all sessions.  One of the noted benefits of PHP is that everything in memory is cleaned up after each session.  There are no &#8220;application variables&#8221; (as they&#8217;re called in ASP) where you can set up a variable that exists over multiple sessions.</p>
<p>This doesn&#8217;t mean there aren&#8217;t ways to implement functionality similar to what you&#8217;re looking for though.  PHP has the session_set_save_handler() method that can help save a user&#8217;s session to a database or file.  You can read about it here:</p>
<p><a href="http://www.php.net/session_set_save_handler" rel="nofollow">session_set_save_handler() documentation</a></p>
<p>Here&#8217;s an implementation without using the session_set_save_handler() function:</p>
<p><a href="http://www.leosingleton.com/projects/code/phpapp/" rel="nofollow">Application variables in PHP</a></p>
<p>And if you&#8217;re interested in hacking up some threading in PHP, here&#8217;s an example:</p>
<p><a href="http://www.webforumz.com/php-forum/12595-multithreaded-php.htm" rel="nofollow">Multi-threaded PHP</a></p>
<p>Needless to say, none of these options are super-duper pretty, but that&#8217;s not really PHP&#8217;s niche.</p>
<p>Anyone else want to comment? Please, I invite you to join&#8230;.the intimate conversation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott</title>
		<link>http://aaronhardy.com/php/object-oriented-php-a-guide-for-fellow-isys-junkies/#comment-23</link>
		<dc:creator>Scott</dc:creator>
		<pubDate>Wed, 08 Aug 2007 14:38:58 +0000</pubDate>
		<guid isPermaLink="false">http://intimateconversations.aaronhardy.com/uncategorized/object-oriented-php-a-guide-for-fellow-isys-junkies/#comment-23</guid>
		<description>Hi Aaron, you did this tutorial just in time for me! I decided to teach myself PHP and good tutorials on using patterns and OOP in PHP is hard to find. I do want to point out that in Intex DAO's were not static classes, we used the singleton pattern to instantiate a DAO once and then passed a reference to the DAO around. Though I've found tutorials on the web showing ways of implementing the singleton pattern in PHP, I cannot find anyone addressing the issue of how to make sure a object is only created once given that in PHP you cannot use "synchronized" key word to insure that a function isn't called multiple times at the exact same time.

Also, and more important to me, I would like to understand how to create objects and classes that are instantiated and then used across all sessions. for example, if I create a class that has a static variable called "$counter" that starts and 0 and gets incremented every time a function in the class is called, the first time a page is loaded, the counter will increment to 1, the next time a the page is loaded, the object appears to be destroyed and recreated thus the counter is reset to 0 and will never be incremented past 1. Is it possible to create objects in PHP that can be passed around to all sessions that may be connected to the server?</description>
		<content:encoded><![CDATA[<p>Hi Aaron, you did this tutorial just in time for me! I decided to teach myself PHP and good tutorials on using patterns and OOP in PHP is hard to find. I do want to point out that in Intex DAO&#8217;s were not static classes, we used the singleton pattern to instantiate a DAO once and then passed a reference to the DAO around. Though I&#8217;ve found tutorials on the web showing ways of implementing the singleton pattern in PHP, I cannot find anyone addressing the issue of how to make sure a object is only created once given that in PHP you cannot use &#8220;synchronized&#8221; key word to insure that a function isn&#8217;t called multiple times at the exact same time.</p>
<p>Also, and more important to me, I would like to understand how to create objects and classes that are instantiated and then used across all sessions. for example, if I create a class that has a static variable called &#8220;$counter&#8221; that starts and 0 and gets incremented every time a function in the class is called, the first time a page is loaded, the counter will increment to 1, the next time a the page is loaded, the object appears to be destroyed and recreated thus the counter is reset to 0 and will never be incremented past 1. Is it possible to create objects in PHP that can be passed around to all sessions that may be connected to the server?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Hardy</title>
		<link>http://aaronhardy.com/php/object-oriented-php-a-guide-for-fellow-isys-junkies/#comment-22</link>
		<dc:creator>Aaron Hardy</dc:creator>
		<pubDate>Wed, 08 Aug 2007 12:25:08 +0000</pubDate>
		<guid isPermaLink="false">http://intimateconversations.aaronhardy.com/uncategorized/object-oriented-php-a-guide-for-fellow-isys-junkies/#comment-22</guid>
		<description>Hey Michael, thanks for joining the intimate conversation!  I guess I should have been more clear on my explanation (which I've since changed), but I've always thought PHP's attempt at supporting method overloading is pretty weak sauce--more of a hack then true, native overloading as found in other languages (like you noted.)  So when I said there are hacks to support the functionality, I guess I just grouped PHP's way of overloading in with it.

For those of you who may be interested in the functionality Michael's talking about, here's &lt;a href="http://us.php.net/manual/en/language.oop5.overloading.php" target="_blank" rel="nofollow"&gt;PHP's documentation on overloading&lt;/a&gt;.

In any case, it'd probably be fair to remove overloading from my "not supported" list and actually dedicate a section to explaining how it is (kind of) supported in PHP.  Thanks for bringing up the issue!  I hope you enjoy the rest of the article!</description>
		<content:encoded><![CDATA[<p>Hey Michael, thanks for joining the intimate conversation!  I guess I should have been more clear on my explanation (which I&#8217;ve since changed), but I&#8217;ve always thought PHP&#8217;s attempt at supporting method overloading is pretty weak sauce&#8211;more of a hack then true, native overloading as found in other languages (like you noted.)  So when I said there are hacks to support the functionality, I guess I just grouped PHP&#8217;s way of overloading in with it.</p>
<p>For those of you who may be interested in the functionality Michael&#8217;s talking about, here&#8217;s <a href="http://us.php.net/manual/en/language.oop5.overloading.php" target="_blank" rel="nofollow">PHP&#8217;s documentation on overloading</a>.</p>
<p>In any case, it&#8217;d probably be fair to remove overloading from my &#8220;not supported&#8221; list and actually dedicate a section to explaining how it is (kind of) supported in PHP.  Thanks for bringing up the issue!  I hope you enjoy the rest of the article!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Jackson</title>
		<link>http://aaronhardy.com/php/object-oriented-php-a-guide-for-fellow-isys-junkies/#comment-21</link>
		<dc:creator>Michael Jackson</dc:creator>
		<pubDate>Wed, 08 Aug 2007 03:05:06 +0000</pubDate>
		<guid isPermaLink="false">http://intimateconversations.aaronhardy.com/uncategorized/object-oriented-php-a-guide-for-fellow-isys-junkies/#comment-21</guid>
		<description>Nice site you have here Aaron! There's just one small point that I think you might be interested in. You mentioned that PHP doesn't support object overloading, but it actually does. Several special methods can be set up on objects, including __get, __set, and __call. This may not be the same implementation as is found in other languages, but it is overloading. Check it out.</description>
		<content:encoded><![CDATA[<p>Nice site you have here Aaron! There&#8217;s just one small point that I think you might be interested in. You mentioned that PHP doesn&#8217;t support object overloading, but it actually does. Several special methods can be set up on objects, including __get, __set, and __call. This may not be the same implementation as is found in other languages, but it is overloading. Check it out.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
<br />
<b>Warning</b>:  stristr() [<a href='function.stristr'>function.stristr</a>]: Empty delimiter in <b>/home/.navyblue/aaronius/aaronhardy.com/wp-content/plugins/wassup/wassup.php</b> on line <b>2093</b><br />
