<?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>Eclectic Thoughts &#187; Technology</title>
	<atom:link href="http://www.eclecticthoughts.com/category/technology/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.eclecticthoughts.com</link>
	<description></description>
	<lastBuildDate>Sun, 03 Jan 2010 14:03:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>The Most Amazing Application Ever</title>
		<link>http://www.eclecticthoughts.com/2009/12/the-most-amazing-application-ever/</link>
		<comments>http://www.eclecticthoughts.com/2009/12/the-most-amazing-application-ever/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 15:21:22 +0000</pubDate>
		<dc:creator>Kieran</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.eclecticthoughts.com/2009/12/the-most-amazing-application-ever/</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>Wow, I am really loving the new version of ________!  It has been improved so much since the last version.  It ___________ and ___________ like never before.  My favorite part though, they added the ability to ___________.  I&#8217;ve never seen anything ___________ before, so of course I was very impressed.  Even better though, you can now ___________.  I&#8217;m also quickly becoming a fan of the new ___________ that they added.  (Yay, nondisclosure agreements!)</p>
<div>Trust me; you&#8217;ll love it too&#8230; some day.</div>
]]></content:encoded>
			<wfw:commentRss>http://www.eclecticthoughts.com/2009/12/the-most-amazing-application-ever/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Splitting Bound Domains &#8211; Keeping Everyone Happy</title>
		<link>http://www.eclecticthoughts.com/2009/11/splitting-bound-domains-keeping-everyone-happy/</link>
		<comments>http://www.eclecticthoughts.com/2009/11/splitting-bound-domains-keeping-everyone-happy/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 15:48:30 +0000</pubDate>
		<dc:creator>Kieran</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.eclecticthoughts.com/?p=115</guid>
		<description><![CDATA[Having two domains mirroring one another, I wanted to split them up and actually use them for different purposes. But how can one safely split apart the domains without upsetting the folks and search engines referencing the domain that is going to be used for a new purpose? It turns out rather easily! Just to [...]]]></description>
			<content:encoded><![CDATA[<p>Having two domains mirroring one another, I wanted to split them up and actually use them for different purposes.  But how can one safely split apart the domains without upsetting the folks and search engines referencing the domain that is going to be used for a new purpose?  It turns out rather easily!<br />
<span id="more-115"></span></p>
<p>Just to make things easier to understand, I will share that <a href="http://www.eclecticthoughts.com">www.eclecticthoughts.com</a> and <a href="http://www.kieransmith.net">www.kieransmith.net</a> pointed to the same site, and explain that I wanted to use www.kieransmith.net for a new site &#8211; a single page listing all my &#8216;homes&#8217; on the &#8216;net.  I knew that search engines and friends (and probably some other folks) were referencing content on the www.kieransmith.net domain, so if I were to simply remove the mirroring, they would end up getting 404 pages if they tried to access the pages there.</p>
<p>The first thing to do is make sure that the new site has a custom 404 page; the browser should show a page, and not an error when someone hits a page that doesn&#8217;t exist.  If you don&#8217;t have this set up, it is rather easy to do.  I use PHP as my programming language of choice, so modify these to suite your needs if you use a different language.  To have the browser show a custom 404 page, simply add the following line to either your virtual-host entry or a .htaccess file in your document root:</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">ErrorDocument</span> <span style="color: #ff0000;">404</span> /404.php</pre></div></div>

<p>Make sure you create your 404 file, too.  It won&#8217;t do anyone any good if you point folks who can&#8217;t find a page to another page that doesn&#8217;t exist!  By using PHP for our 404 page, we&#8217;re able to put some smarts behind the page, and maybe even serve up the &#8220;lost&#8221; page.  Using a mix of <a href="http://www.php.net/curl">cURL</a> and <a href="http://www.php.net/manual/en/function.header.php">headers</a> in PHP, one can check if a page exists somewhere else, and if it does, redirect the visitor to the now-not-lost page.  Here&#8217;s the script I came up with:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;http://www.eclecticthoughts.com&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;+&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;REQUEST_URI&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #990000;">curl_exec</span>\<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$ch</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$info</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_getinfo</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$ch</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$info</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;http_code&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;200&quot;</span> <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// If we got a 200 status code (versus a 404), the page was found.</span>
		<span style="color: #666666; font-style: italic;">// We can now throw a 301 (Moved Permanently) and redirect to the new address.</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Location: http://www.eclecticthoughts.com&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;+&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;REQUEST_URI&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">301</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Put your 'Oops, we lost your page content here.</span>
	<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><em>Note:</em> The line &#8220;curl_exec\( $ch );&#8221; should <strong>not</strong> have the slash in it.  Adding this slash was the only way I could sneak this line of code into the post.  Apparently all the other code goes through just fine, but this one borked WordPress when I posted it.</p>
<p>It is that easy!  Of course, you need the curl PHP extension set up, and if you don&#8217;t have access to your virtual-host file, you&#8217;ll need your hosting provider to allow .htaccess files, but most should have both of these conveniently set up, so the code provided should work &#8216;out of the box.&#8217;</p>
<p>Let me know if you have any additional ideas or run into any problems.  I&#8217;d love to hear from you!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.eclecticthoughts.com/2009/11/splitting-bound-domains-keeping-everyone-happy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction to Object Oriented PHP</title>
		<link>http://www.eclecticthoughts.com/2009/03/introduction-to-object-oriented-php/</link>
		<comments>http://www.eclecticthoughts.com/2009/03/introduction-to-object-oriented-php/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 03:41:22 +0000</pubDate>
		<dc:creator>Kieran</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.kieransmith.net/?p=89</guid>
		<description><![CDATA[Over the next few php articles I write, I hope to delve into the depths of PHP and some of the ways it can best be utilized. To get started, we&#8217;ll begin with object oriented PHP programming. If this concept is new to you, have no fear. As long as you have an understanding of [...]]]></description>
			<content:encoded><![CDATA[<p>Over the next few php articles I write, I hope to delve into the depths of PHP and some of the ways it can best be utilized.  To get started, we&#8217;ll begin with object oriented PHP programming.  If this concept is new to you, have no fear.  As long as you have an understanding of PHP in general, it is really rather simple, especially if we step through it bit by bit.</p>
<p><span id="more-89"></span></p>
<p>Before we get too much farther, it is important to note that the code I&#8217;m going to show you won&#8217;t work in any version of PHP prior to version 5.  PHP 4 is quickly being phased out as 6 is right around the corner.  Smart move by the PHP authors!</p>
<p>You&#8217;ve probably gathered that object oriented programming is, well, oriented around objects.  What is an object I hear you asking?  Simple.  An object is a person, place, or thing&#8230;  a noun.  See, I told you this stuff was easy.  So lets think of some things.  An airplane.  A car.  A bank account.  A shopping cart.  A book.  Let&#8217;s take that book example and run with it.</p>
<p>A book, as with any other object, can have attributes.  A book has a title, a set number of pages, an author, and maybe even a bookmark letting you know what page you are currently.  You can also do things with a book, such as flip to the next page, flip back a page, or maybe even skip ahead to the last page to get a sneak peak at how things will end up.</p>
<p>Can we represent all of this in PHP code?  Of course!  We just need to define these attributes and plug in the functionality into what is called a class.  A class defines your object.  You create a new class with the word &#8220;class&#8221; followed by the name of your object.  As an object has structure and is defined, PHP needs to know where the class definition starts and stops.  You do this with our good friends, the curly braces.  Our empty class, defining the book object, will look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Book
<span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>At the top of your class, just after the first curly brace, we will set the attributes of the book.  These variables should always be defined at the top of your class and, for the sake of this article, can be public (available from outside the class) or private (only available to code inside the class).  There are other options, but we&#8217;ll save those for another day.  Simply append the work &#8220;public&#8221; or &#8220;private&#8221; before the variable, like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Book
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span>     <span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span>    <span style="color: #000088;">$author</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span>
    <span style="color: #000000; font-weight: bold;">private</span>    <span style="color: #000088;">$number_of_pages</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span>    <span style="color: #000088;">$current_page</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Most of the variables aren&#8217;t set to anything specific yet, as we do not know what actual book it is going to represent until it is created, but more on that later.  We do know, however, that we always start reading a book from the first page, so we can go ahead and set that variable right away.</p>
<p>Now let&#8217;s put some brains behind our new book class.  Class methods, also commonly called functions, are the only way to handle functionality.  You cannot have PHP code just floating around willy-nilly.  These functions can also be noted as being public or private.  Again, there are other options, but we&#8217;ll save those for another article.</p>
<p>In trying to keep the craziness to a minimum, we need to think this through.  We want to be able to set the attributes of the book,  see the title of the book, who wrote it, and flip to the next page, flip back a page, and jump to the end of the book.  Notice there are a lot of functions that deal with pages?  Why rewrite code to handle page turning again and again when we can simply write one function to handle the page turning and then have simple functions make use of that function?  Confused?  It will be easier to understand when you see it in action.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Book
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span>     <span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span>    <span style="color: #000088;">$author</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span>
    <span style="color: #000000; font-weight: bold;">private</span>    <span style="color: #000088;">$number_of_pages</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span>    <span style="color: #000088;">$current_page</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> get_author<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">author</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> go_to_page<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$page</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">current_page</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$page</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> next_page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">go_to_page</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">current</span><span style="color: #339933;">-</span>page <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> previous_page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">go_to_page</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">current</span><span style="color: #339933;">-</span>page <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> jump_to_last_page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Sorry Charlie.  No skipping ahead!&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Whoa, there&#8217;s a lot of new stuff in there.  Don&#8217;t worry.  Remember, nice and simple, slow and steady.  First off, note that most functions are set to pubic.  This allows us to call them from outside of the code in the class, like from the code in which the object is going to be created.  However, the go_to_page() function is marked as private.  If you try to call it from outside of the class, it will blow up on you.  This is convenient to keep people skipping around from random page to random page, but yet lets us go to specific pages from within the class proper.  This keeps the power of going to pages in the control of the class, and ultimately in the hands of whoever is writing the class.</p>
<p>I&#8217;m sure you noticed the use of $this as well.  Since objects live in their own little world, and many instances of an object can be created at any given time, you need to specify that you are talking about THIS specific instance of the book.  The functions are not global in scope; you could not call the next_page() function from just anywhere in your application.  It must be associated with a specific book, or we wouldn&#8217;t know how many pages were in the book to even know if we could turn the page again.</p>
<p>As it is now, even when we create a book object now, we don&#8217;t know how many pages are in it, since we have no way of setting the attributes in the book yet.  Let&#8217;s fix that with what is called the &#8220;constructor&#8221; of the class.  It should be the first function in the class, and can do anything you want it to do &#8211; or nothing at all.  You define your constructor by creating a function named __construct.  The two underscores are used by PHP to say &#8220;Hey, I&#8217;ve got a special function I&#8217;m defining for you here.&#8221;  There&#8217;s several of these magic functions, but we&#8217;ll stick with the constructor for now.  Oh, what&#8217;s that?  Why&#8217;s the constructor magical?  Well, you see the constructor gets called automagically when you instantiate the object.  Because of this, you can pass the variables into the constructor at the time of instantiating the class.  We&#8217;ll get to that in a minute.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Book
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span>     <span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span>    <span style="color: #000088;">$author</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span>
    <span style="color: #000000; font-weight: bold;">private</span>    <span style="color: #000088;">$number_of_pages</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span>    <span style="color: #000088;">$current_page</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$title</span><span style="color: #339933;">,</span> <span style="color: #000088;">$author</span><span style="color: #339933;">,</span> <span style="color: #000088;">$number_of_pages</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$title</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">author</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$author</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">number_of_pages</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$number_of_pages</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> get_author<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">author</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> go_to_page<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$page</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">current_page</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$page</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> next_page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">go_to_page</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">current</span><span style="color: #339933;">-</span>page <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> previous_page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">go_to_page</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">current</span><span style="color: #339933;">-</span>page <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> jump_to_last_page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Sorry Charlie.  No skipping ahead!&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Sure, we&#8217;ve done absolutely no validation in any of these functions; I leave that up to you to develop.  Realistically, you wouldn&#8217;t be passing in all these attributes anyway, but would rather likely be sending in a book ID and then looking up the attributes in a database.  But we&#8217;re keeping things simple here, after all.</p>
<p>Notice that we can reference all the passed in variables directly by their name.  But remember $this?  Here we can see how a local variable and a class variable can co-mingle.  You take the title and set it to be the title of THIS specific instance of a book.  Still with me?</p>
<p>Great, we&#8217;ve got all our functionality in place, so let&#8217;s start playing with it.</p>
<p>Somewhere else in your application, you want people to be able to be able to work with books.  Once you know what book someone is looking for, you can create a new instance of the book object for it and assign it to a variable.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$our_book</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Book<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;The Cat In The Hat&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Dr. Suess&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;20&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We&#8217;ve just created a book called The Cat In The Hat by Dr. Suess that has 20 pages and has all the functionality a book should have.  You can&#8217;t call the functions using $this from outside the class, however, as that wouldn&#8217;t allow you to have multiple books open at the same time.  Instead, we use the variable to which we just assigned the new book.</p>
<p>To display the author, since the variable is private within the class, we must use the get_author() function.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$our_book</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_author</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The title is public, so we can simply pull that out of the class without a function, directly by variable name, since we defined it at the top of the class.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$our_book</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">;</span></pre></div></div>

<p>We&#8217;ve just finished reading page one of our book, so let&#8217;s turn the page.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$our_book</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">next_page</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Not a whole lot of text on these pages.  Flip to the next one.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$our_book</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">next_page</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Ahhh, green eggs.  Yummy!  By creating a class for our books, and putting all book functions in that class, we have been granted two very important benefits when developing an application:</p>
<ul>
<li>A book can be accessed anywhere again and again.  Let&#8217;s say you have a page that lists all your books and each of those listings links to a page about each specific book.  There is no need to duplicate any of the functionality.  It is all wrapped up in a pretty bow in the book class.</li>
<li>Because all the book functions are together in one class, you only have one place to go if you want to modify your book functionality or add to it.  Two years from now, you won&#8217;t want to go through twenty files searching for any code dealing with books; you&#8217;ll want to know that any book code is going to be in the book class.  Sure, other files will reference the book class, but lots of references to one file containing all your book logic sure beats having the logic scattered across several different files.</li>
</ul>
<p>Hopefully this article made sense.  If it didn&#8217;t, feel free to come at me with a giant stick or, preferably, ask questions.  I&#8217;ll be more than happy to answer them.  This is an important concept to grasp in PHP and once you get used to it, you will wonder how you ever survived without classes in your life.  Learning even just this little bit about object oriented programming allows us to open the door to so many other cool ways of doing things.  I look forward to sharing them with you!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.eclecticthoughts.com/2009/03/introduction-to-object-oriented-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Yawn&#8230; Microsoft Announces Free Anti-Virus/Anti-Malware Solution</title>
		<link>http://www.eclecticthoughts.com/2009/01/yawn-microsoft-announces-free-anti-virusanti-malware-solution/</link>
		<comments>http://www.eclecticthoughts.com/2009/01/yawn-microsoft-announces-free-anti-virusanti-malware-solution/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 15:32:27 +0000</pubDate>
		<dc:creator>Kieran</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.kieransmith.net/?p=78</guid>
		<description><![CDATA[Back in November, Microsoft announced an anti-malware application (currently code-named Morro) will be released for free in the second half of 2009.  What do I say?  It&#8217;s about time! Microsoft already has an anti-malware solution, however.  It is called OneCare, and they charge fifty bucks for it &#8211; yearly.  It hasn&#8217;t been doing so well.  [...]]]></description>
			<content:encoded><![CDATA[<p>Back in November, Microsoft <a title="Press Release" href="http://www.microsoft.com/presspass/press/2008/nov08/11-18NoCostSecurityPR.mspx" target="_blank">announced</a> an anti-malware application (currently code-named Morro) will be released for free in the second half of 2009.  What do I say?  It&#8217;s about time!</p>
<p>Microsoft already has an anti-malware solution, however.  It is called <a title="Windows Live OneCare" href="http://www.google.com/url?sa=t&amp;source=web&amp;ct=res&amp;cd=1&amp;url=http%3A%2F%2Fonecare.live.com%2F&amp;ei=OPRxSbWtINW5twf1y8DnCA&amp;usg=AFQjCNEkpLx667SiAH6-cuLGxKEgujEsvg&amp;sig2=FXGU0MD2cSByZQINrHhMJg" target="_blank">OneCare</a>, and they charge fifty bucks for it &#8211; yearly.  It hasn&#8217;t been doing so well.  And why should it?</p>
<p>As a consumer, when I buy something, I expect it to work.  If it doesn&#8217;t, it seems to me there is obviously a problem.</p>
<p>Viruses exploit vulnerabilities in the operating system; the fewer the vulnerabilities, the fewer the viruses running rampant on the Internet.  Essentially, Microsoft is charging to fix problems caused by their own software.  That seems honorable, no?  Needless to say, I&#8217;m not jumping for joy at the news of Morro coming down the pipeline.  Should it not be the responsibility of Microsoft to either release secure operating systems &#8211; or repair the damage caused by insecurities?</p>
<p>What if we were talking about cribs?  Would you shrug your shoulders as your infant tumbles to the ground, risking life and limb, in a poorly constructed crib?  We as consumers have been trained to have different expectations from different industries.  Granted, data is nothing more than ones and zeros, but I know few people who would see losing their computer to a virus as anything but detrimental.  Why have we come to not expect the same quality of software providers that we expect from all other businesses?</p>
<p>Regardless, I think we&#8217;d all be crazy not to install Morro when it comes out.  You can&#8217;t beat the price, and it certainly can&#8217;t make things worse, right?  Well, this is assuming it doesn&#8217;t have vulnerabilities of its own.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.eclecticthoughts.com/2009/01/yawn-microsoft-announces-free-anti-virusanti-malware-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Joy of Technology</title>
		<link>http://www.eclecticthoughts.com/2009/01/the-joy-of-technology/</link>
		<comments>http://www.eclecticthoughts.com/2009/01/the-joy-of-technology/#comments</comments>
		<pubDate>Sun, 11 Jan 2009 19:43:43 +0000</pubDate>
		<dc:creator>Kieran</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.kieransmith.net/?p=75</guid>
		<description><![CDATA[After a good weekend of coding, designing, tweaking, fetching content from other sites&#8230;  I think I&#8217;m past the &#8220;moving in&#8221; stage and can now sit back, relax, and enjoy.  The menus at the top of the page are ripped right from kieransmith.net (well, the old kieransmith.net) except for the photos, which come from eclecticthoughts.com before [...]]]></description>
			<content:encoded><![CDATA[<p>After a good weekend of coding, designing, tweaking, fetching content from other sites&#8230;  I think I&#8217;m past the &#8220;moving in&#8221; stage and can now sit back, relax, and enjoy.  The menus at the top of the page are ripped right from kieransmith.net (well, the old kieransmith.net) except for the photos, which come from eclecticthoughts.com before I gank that down and mirror this blog there as well.</p>
<p>So, I thought I&#8217;d get creative and see if I could use the RSS feed from my blog to get stuff into Facebook.  You know, why duplicate efforts?  So in my quest I discovered two nifty apps.</p>
<p>For wordpress.org participants (you host your own blog), there is <a title="Wordbook" href="http://wordpress.org/extend/plugins/wordbook/" target="_blank">Wordbook</a> &#8211; a nifty app that integrates WordPress postings into Facebook.</p>
<p>Don&#8217;t host your own blog?  You&#8217;re hosting it at wordpress.com instead?  Not a problem!  Check out the <a title="WordPress.com Facebook App" href="http://www.facebook.com/apps/application.php?id=2373049596" target="_blank">WordPress.com Facebook application</a>.</p>
<p>Even having worked on this sort stuff for 14 years now, with the last few years most definitely being full of &#8220;application-based&#8221; projects, technology never ceases to amaze me.  If you can think of it, someone else has already done it.  The real trick is doing it better!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.eclecticthoughts.com/2009/01/the-joy-of-technology/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
