<?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>Dominik Winter&#039;s Blog &#187; php</title>
	<atom:link href="http://blog.edge-project.org/category/programming-language/php-programming-language/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.edge-project.org</link>
	<description></description>
	<lastBuildDate>Fri, 01 Jul 2011 20:45:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>Multiple Inheritance in PHP</title>
		<link>http://blog.edge-project.org/2009/12/20/multiple-inheritance-in-php/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://blog.edge-project.org/2009/12/20/multiple-inheritance-in-php/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 17:26:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.edge-project.org/?p=137</guid>
		<description><![CDATA[With the magic of __call() it is possible to do multiple inheritance in PHP. This example is more then a mixin pattern. It can also call protected and private methods from inherited classes.



That's all! Now the usage:

We have two simple base classes, Bird and Horse, which have some methods.



Now we want a new class named ...]]></description>
			<content:encoded><![CDATA[<p>With the magic of __call() it is possible to do multiple inheritance in PHP. This example is more then a mixin pattern. It can also call protected and private methods from inherited classes.</p>
<pre class="brush: php; title: ; notranslate">&lt;?php

abstract class Inheritance {
    private $_inheritances = array();

    public function __call($method, array $arguments = array()) {
        // Here you can handle the calls. Maybe you don't want to call
        // every found method but only the first or the last ...
        foreach ($this-&gt;_inheritances as $inheritance) {
            $inheritance-&gt;invoke($method, $arguments);
        }
    }

    public function invoke($method, $arguments) {
        if (method_exists($this, $method) === true) {
            return call_user_func_array(array($this, $method), $arguments);
        }
    }

    protected function _addInheritance(Inheritance $inheritance) {
        $this-&gt;_inheritances[get_class($inheritance)] = $inheritance;
    }
}</pre>
<p>That&#8217;s all! Now the usage:</p>
<p>We have two simple base classes, Bird and Horse, which have some methods.</p>
<pre class="brush: php; title: ; notranslate">/**
 * first base class
 */
class Bird extends Inheritance {
    public function chirp() {
        echo &quot;&lt;br/&gt;chirp ..&quot;;
    }

    public function fly() {
        echo &quot;&lt;br/&gt;fly ..&quot;;
    }

    protected function _eat() {
        echo &quot;&lt;br/&gt;eat worms ..&quot;;
    }
}

/**
 * second base class
 */
class Horse extends Inheritance {
    public function whinny() {
        echo &quot;&lt;br/&gt;whinny ..&quot;;
    }

    protected function _eat() {
        echo &quot;&lt;br/&gt;eat hay ..&quot;;
    }
}</pre>
<p>Now we want a new class named Pegasus that implements all methods from Bird and Horse. The only thing we have to do is to inherit from Inheritance and add the two base classes with _addInheritance().</p>
<pre class="brush: php; title: ; notranslate">class Pegasus extends Inheritance {
    public function __construct() {
        // bind extented classes
        $this-&gt;_addInheritance(new Bird);
        $this-&gt;_addInheritance(new Horse);
    }

    public function eat() {
        // works with protected methods, too
        $this-&gt;_eat();
    }
}

$pegasus = new Pegasus;
$pegasus-&gt;chirp();
$pegasus-&gt;fly();
$pegasus-&gt;whinny();
$pegasus-&gt;eat();</pre>
<p>Output:</p>
<pre class="brush: plain; title: ; notranslate">chirp ..
fly ..
whinny ..
eat worms ..
eat hay ..</pre>
<p class="wp-flattr-button"></p> <p><a href="http://blog.edge-project.org/?flattrss_redirect&amp;id=137&amp;md5=7affa6636bdb949af1b134c2491ba587" title="Flattr" target="_blank"><img src="http://blog.edge-project.org/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.edge-project.org/2009/12/20/multiple-inheritance-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chaining Variables</title>
		<link>http://blog.edge-project.org/2009/06/21/chaining-variables/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://blog.edge-project.org/2009/06/21/chaining-variables/#comments</comments>
		<pubDate>Sun, 21 Jun 2009 13:57:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.edge-project.org/?p=5</guid>
		<description><![CDATA[Do you have always asked yourself how to chain variables to make a sentence?

In the magic __get()-method the variable names will be collected, and finally the echo "calls" the __toString()-method.



Usage:



Output:

]]></description>
			<content:encoded><![CDATA[<p>Do you have always asked yourself how to chain variables to make a sentence?</p>
<p>In the magic __get()-method the variable names will be collected, and finally the echo &#8220;calls&#8221; the __toString()-method.</p>
<pre class="brush: php; title: ; notranslate">&lt;?php

class Sentence {
    protected $_words = array();

    public static function create() {
        return new self;
    }

    public function __get($word) {
        $this-&gt;_words[] = $word;

        return $this;
    }

    public function __toString() {
        return implode(' ', $this-&gt;_words) . '.';
    }
}</pre>
<p>Usage:</p>
<pre class="brush: php; title: ; notranslate">echo Sentence::create()-&gt;All-&gt;your-&gt;base-&gt;are-&gt;belong-&gt;to-&gt;us;</pre>
<p>Output:</p>
<pre class="brush: plain; title: ; notranslate">All your base are belong to us.</pre>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://blog.edge-project.org/2009/06/21/chaining-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

