<?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>http://mrbichel.com &#187; Object Oriented Programming</title>
	<atom:link href="http://mrbichel.com/tag/object-oriented-programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://mrbichel.com</link>
	<description>Johan Bichel Lindegaards personal webspace</description>
	<lastBuildDate>Wed, 08 Sep 2010 14:25:06 +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>Object Oriented WP plugin structure</title>
		<link>http://mrbichel.com/2008/07/oo-wp-plugin-structure/</link>
		<comments>http://mrbichel.com/2008/07/oo-wp-plugin-structure/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 13:59:39 +0000</pubDate>
		<dc:creator>Johan</dc:creator>
				<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://accidentdesigns.com/?p=113</guid>
		<description><![CDATA[When searching the web for WordPress plugin tutorials and introductions the vast majority utilizes procedural programming. However having recently discovered Object Oriented programming in PHP 5 i decided to take another approach to both plugins and themes. When encapsulating plugins or parts of your themes in classes, you create a container for variable, constant and [...]]]></description>
			<content:encoded><![CDATA[<p>When searching the web for WordPress plugin tutorials and introductions the vast majority utilizes procedural programming. However having recently discovered Object Oriented programming in PHP 5 i decided to take another approach to both plugins and themes.</p>

<p>When encapsulating plugins or parts of your themes in classes, you create a container for variable, constant and function names thus avoiding name clashes with the core or with other plugins. You can also encapsulate your class in a statement checking if the class already exists to ensure that in the rare case of a name collision your plugin will not initialize and crash the WordPress installation.</p>

<p>Here is a simple example
<pre lang="php" line="1">
&lt; ?php
// Plugin Name: Text Barking Dog</p>

<p>if (!class_exists('OurWpPluginDog')) {
    class OurWpPluginDog {
        function __construct() {
            $this->text = "wuff wuff";
        }
        function bark() {
            echo '<!--' . $this->text . '-->';
        }
    }
    $dog = new OurWpPluginDog;
    add_action('wp_footer', array(&amp;$dog, 'bark'));
}
</pre></p>

<p>This plugin will insert &#8220;wuff wuff&#8221; as an html comment at the hook wp_footer. The __construct function runs when the class is constructed you can also place your actions and filters here, if you do you simply reference array(&amp;$this &#8230; instead.</p>

<p>Object oriented programming encourages DRY &#8211; it simply makes it more convenient to reuse your code. As your plugin grows you will also find it easier to get an overview of the code.</p>
]]></content:encoded>
			<wfw:commentRss>http://mrbichel.com/2008/07/oo-wp-plugin-structure/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
