<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Method Overloading in PHP5</title>
	<atom:link href="http://www.dinke.net/blog/en/2007/08/01/method-overloading-in-php5/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dinke.net/blog/en/2007/08/01/method-overloading-in-php5/</link>
	<description>Dinke&#039;s Personal Blog</description>
	<lastBuildDate>Fri, 13 Jan 2012 17:23:11 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: umer singhera</title>
		<link>http://www.dinke.net/blog/en/2007/08/01/method-overloading-in-php5/comment-page-1/#comment-8333</link>
		<dc:creator>umer singhera</dc:creator>
		<pubDate>Sat, 25 Jun 2011 12:16:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.dinke.net/blog/2007/08/01/method-overloading-in-php5/sr/#comment-8333</guid>
		<description>nice</description>
		<content:encoded><![CDATA[<p>nice</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sherman Unkefer</title>
		<link>http://www.dinke.net/blog/en/2007/08/01/method-overloading-in-php5/comment-page-1/#comment-5326</link>
		<dc:creator>Sherman Unkefer</dc:creator>
		<pubDate>Fri, 14 Jan 2011 15:57:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.dinke.net/blog/2007/08/01/method-overloading-in-php5/sr/#comment-5326</guid>
		<description>Can I use both PHP4 and PHP5 on the same dedicated server?</description>
		<content:encoded><![CDATA[<p>Can I use both PHP4 and PHP5 on the same dedicated server?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Od Informacji do Wiedzy &#187; Archiwum bloga &#187; PHP &#8211; co robić gdy potrzeba coś przeciążyć?</title>
		<link>http://www.dinke.net/blog/en/2007/08/01/method-overloading-in-php5/comment-page-1/#comment-4256</link>
		<dc:creator>Od Informacji do Wiedzy &#187; Archiwum bloga &#187; PHP &#8211; co robić gdy potrzeba coś przeciążyć?</dc:creator>
		<pubDate>Sat, 20 Nov 2010 10:49:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.dinke.net/blog/2007/08/01/method-overloading-in-php5/sr/#comment-4256</guid>
		<description>[...] metod jest użycie magicznych metod. Sposób takiej implementacji można podejrzeć w wpisie &#8220;Method Overloading in PHP5&#8243; na blogu Caught in a Web. Osobiście nie przepadam za tego rodzaju rozwiązaniami. Tak więc w [...]</description>
		<content:encoded><![CDATA[<p>[...] metod jest użycie magicznych metod. Sposób takiej implementacji można podejrzeć w wpisie &#8220;Method Overloading in PHP5&#8243; na blogu Caught in a Web. Osobiście nie przepadam za tego rodzaju rozwiązaniami. Tak więc w [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tanvir</title>
		<link>http://www.dinke.net/blog/en/2007/08/01/method-overloading-in-php5/comment-page-1/#comment-2287</link>
		<dc:creator>Tanvir</dc:creator>
		<pubDate>Sat, 15 May 2010 18:43:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.dinke.net/blog/2007/08/01/method-overloading-in-php5/sr/#comment-2287</guid>
		<description>Hello
I have shown a good example in my blog ( http://blog.actcode.com/2010/05/php-overloading-method-overloading-and.html ).
It&#039;s clearly described there , that how overloading should implement.

Thnaks
Tanvir.</description>
		<content:encoded><![CDATA[<p>Hello<br />
I have shown a good example in my blog ( <a href="http://blog.actcode.com/2010/05/php-overloading-method-overloading-and.html" rel="nofollow">http://blog.actcode.com/2010/05/php-overloading-method-overloading-and.html</a> ).<br />
It&#8217;s clearly described there , that how overloading should implement.</p>
<p>Thnaks<br />
Tanvir.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Deecee</title>
		<link>http://www.dinke.net/blog/en/2007/08/01/method-overloading-in-php5/comment-page-1/#comment-191</link>
		<dc:creator>Deecee</dc:creator>
		<pubDate>Tue, 21 Jul 2009 17:36:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.dinke.net/blog/2007/08/01/method-overloading-in-php5/sr/#comment-191</guid>
		<description>This is really good example of Overloading in PHP, specially given example with Java.

Thanks a Lot.</description>
		<content:encoded><![CDATA[<p>This is really good example of Overloading in PHP, specially given example with Java.</p>
<p>Thanks a Lot.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Forsyth</title>
		<link>http://www.dinke.net/blog/en/2007/08/01/method-overloading-in-php5/comment-page-1/#comment-189</link>
		<dc:creator>Forsyth</dc:creator>
		<pubDate>Sat, 31 Jan 2009 15:29:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.dinke.net/blog/2007/08/01/method-overloading-in-php5/sr/#comment-189</guid>
		<description>Final result:

class MSSSimpleXML {

   const URL = 1;
   const STRING = 2;
   const SIMPLEXML = 3;

   ...

   function MSSSimpleXML($data, $mode=self::STRING ) {

      switch ($mode)
      {
         case self::STRING:
            ...
            break;

         case self::URL:
            ...
            break;

         case self::SIMPLEXML:
            ...
            break;
      }
   }
   ...
}

Makes default constructor assume STRING.

Usage:

   // constructor where data is xml in string form
   $xml = new MSSSimpleXML( $data );

   // same
   $xml = new MSSSimpleXML( $data, MSSSimpleXML::STRING );

   // constructor where data is url pointing to xml
   $xml = new MSSSimpleXML( $data, MSSSimpleXML::URL );

   // constructor where data is SimpleXMLElement object
   $xml = new MSSSimpleXML( $data, MSSSimpleXML::SIMPLEXML );

If you had additional arguments that varied by mode you could add an associative array of arguments...

peace,
-Forsyth</description>
		<content:encoded><![CDATA[<p>Final result:</p>
<p>class MSSSimpleXML {</p>
<p>   const URL = 1;<br />
   const STRING = 2;<br />
   const SIMPLEXML = 3;</p>
<p>   &#8230;</p>
<p>   function MSSSimpleXML($data, $mode=self::STRING ) {</p>
<p>      switch ($mode)<br />
      {<br />
         case self::STRING:<br />
            &#8230;<br />
            break;</p>
<p>         case self::URL:<br />
            &#8230;<br />
            break;</p>
<p>         case self::SIMPLEXML:<br />
            &#8230;<br />
            break;<br />
      }<br />
   }<br />
   &#8230;<br />
}</p>
<p>Makes default constructor assume STRING.</p>
<p>Usage:</p>
<p>   // constructor where data is xml in string form<br />
   $xml = new MSSSimpleXML( $data );</p>
<p>   // same<br />
   $xml = new MSSSimpleXML( $data, MSSSimpleXML::STRING );</p>
<p>   // constructor where data is url pointing to xml<br />
   $xml = new MSSSimpleXML( $data, MSSSimpleXML::URL );</p>
<p>   // constructor where data is SimpleXMLElement object<br />
   $xml = new MSSSimpleXML( $data, MSSSimpleXML::SIMPLEXML );</p>
<p>If you had additional arguments that varied by mode you could add an associative array of arguments&#8230;</p>
<p>peace,<br />
-Forsyth</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Forsyth</title>
		<link>http://www.dinke.net/blog/en/2007/08/01/method-overloading-in-php5/comment-page-1/#comment-188</link>
		<dc:creator>Forsyth</dc:creator>
		<pubDate>Sat, 31 Jan 2009 14:55:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.dinke.net/blog/2007/08/01/method-overloading-in-php5/sr/#comment-188</guid>
		<description>Now that I look at it I believe I&#039;ll change it to create a single &quot;mode&quot; flag that takes constants:

class MSSSimpleXML {
   const URL = 1;
   const STRING = 2;
   const SIMPLEXML = 3;

   function MSSSimpleXML( $xml, $mode ) {
    ...
   }
}

Usage:

  ...
  new MSSSimpleXML( $xml, MSSSimpleXML::STRING );
  ...

Would be cleaner I think.</description>
		<content:encoded><![CDATA[<p>Now that I look at it I believe I&#8217;ll change it to create a single &#8220;mode&#8221; flag that takes constants:</p>
<p>class MSSSimpleXML {<br />
   const URL = 1;<br />
   const STRING = 2;<br />
   const SIMPLEXML = 3;</p>
<p>   function MSSSimpleXML( $xml, $mode ) {<br />
    &#8230;<br />
   }<br />
}</p>
<p>Usage:</p>
<p>  &#8230;<br />
  new MSSSimpleXML( $xml, MSSSimpleXML::STRING );<br />
  &#8230;</p>
<p>Would be cleaner I think.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Forsyth</title>
		<link>http://www.dinke.net/blog/en/2007/08/01/method-overloading-in-php5/comment-page-1/#comment-187</link>
		<dc:creator>Forsyth</dc:creator>
		<pubDate>Sat, 31 Jan 2009 14:38:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.dinke.net/blog/2007/08/01/method-overloading-in-php5/sr/#comment-187</guid>
		<description>Unfortunate problem, especially with constructors.

The magic methods make me feel a bit queasy.

One solution that dawned on me this morning is to keep a single method but add booleans to dictate the &quot;type&quot;.

For example, my original constructor:

class MSSSimpleXML {
function MSSSimpleXML($data, $isURL = FALSE) {
...
}
}

The purpose of this class is to wrap a SimpleXMLElement object. The constructor allowed you to say whether $data was a URL or an XML string.

Now I wanted a constructor that would allow you to construct a MSSSimpleXML object from a php SimpleXMLElement.

Constructor overloading would have been perfect but instead settled on this:

function MSSSimpleXML($data, $isURL = FALSE, $isSimpleXML = FALSE)

The constructor now has three modes:

1. Build an object from an XML string ($data=[the string], $isURL=FALSE, $isSimpleXML=FALSE)

2. Build an object from a URL that points to XML ($data=[the URL], $isURL=TRUE, $isSimpleXML=FALSE)

3. Build an object from a SimpleXMLElement object ($data=[the SimpleXMLElement instance, $isURL=FALSE, $isSimpleXML=TRUE)

Not terribly beautiful. (It would have to be late and I&#039;d have to be drunk to...)

But...very simple -- which is what PHP is all about.

peace,
-Forsyth</description>
		<content:encoded><![CDATA[<p>Unfortunate problem, especially with constructors.</p>
<p>The magic methods make me feel a bit queasy.</p>
<p>One solution that dawned on me this morning is to keep a single method but add booleans to dictate the &#8220;type&#8221;.</p>
<p>For example, my original constructor:</p>
<p>class MSSSimpleXML {<br />
function MSSSimpleXML($data, $isURL = FALSE) {<br />
&#8230;<br />
}<br />
}</p>
<p>The purpose of this class is to wrap a SimpleXMLElement object. The constructor allowed you to say whether $data was a URL or an XML string.</p>
<p>Now I wanted a constructor that would allow you to construct a MSSSimpleXML object from a php SimpleXMLElement.</p>
<p>Constructor overloading would have been perfect but instead settled on this:</p>
<p>function MSSSimpleXML($data, $isURL = FALSE, $isSimpleXML = FALSE)</p>
<p>The constructor now has three modes:</p>
<p>1. Build an object from an XML string ($data=[the string], $isURL=FALSE, $isSimpleXML=FALSE)</p>
<p>2. Build an object from a URL that points to XML ($data=[the URL], $isURL=TRUE, $isSimpleXML=FALSE)</p>
<p>3. Build an object from a SimpleXMLElement object ($data=[the SimpleXMLElement instance, $isURL=FALSE, $isSimpleXML=TRUE)</p>
<p>Not terribly beautiful. (It would have to be late and I&#8217;d have to be drunk to&#8230;)</p>
<p>But&#8230;very simple &#8212; which is what PHP is all about.</p>
<p>peace,<br />
-Forsyth</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Certifications</title>
		<link>http://www.dinke.net/blog/en/2007/08/01/method-overloading-in-php5/comment-page-1/#comment-190</link>
		<dc:creator>Certifications</dc:creator>
		<pubDate>Fri, 30 Jan 2009 09:57:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.dinke.net/blog/2007/08/01/method-overloading-in-php5/sr/#comment-190</guid>
		<description>Hello, I am learning programming in PHP these days. This easy to understand code helped in learning method overloading in PHP. So thanks a lot.</description>
		<content:encoded><![CDATA[<p>Hello, I am learning programming in PHP these days. This easy to understand code helped in learning method overloading in PHP. So thanks a lot.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Nino</title>
		<link>http://www.dinke.net/blog/en/2007/08/01/method-overloading-in-php5/comment-page-1/#comment-179</link>
		<dc:creator>Michael Nino</dc:creator>
		<pubDate>Mon, 07 Jul 2008 18:47:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.dinke.net/blog/2007/08/01/method-overloading-in-php5/sr/#comment-179</guid>
		<description>Dinke,

Please clean up blog entries. I posted some PHP code but it didn&#039;t escape the content so greater than and less than signs for example are rendering the code for Polad incorrectly. Also, the blog posts an entry *before* you enter the captcha which defeats the purpose of having a captcha. Consequently, there are 2 almost identical blog posts-- second one is correct.

Okay here is the code again....

&lt;pre&gt;
class Word {
	// ...
}

class ExtWord extends Word {
	// ...
}

class MyClass {

	// Method Signature Overloading (Polymorphism)
	function __call($method, $parameters) {
		foreach (get_class_methods(__CLASS__) as $class_method) {
			if (preg_match(&#039;/&#039;.$method.&#039;\d+/&#039;, $class_method)) {
				$reflect_method = new ReflectionMethod(__CLASS__, $class_method);
				if (count($parameters) == $reflect_method-&gt;getNumberOfParameters()) {
					$class_parameters = $reflect_method-&gt;getParameters();
					for ($p=0; $p&lt;count($parameters); $p++) {
						if (get_class($parameters[$p]) == $class_parameters[$p]-&gt;getClass()-&gt;getName()) {
							if ($p == count($parameters)-1) {
								call_user_func_array(array(&amp;$this, $class_method), $parameters);
								break 2; // Method Signature Match
							}
						} else {
							break;
						}
					}
				}
			}
		}
	}

	function hello2(Word $word) {
		// ...
	}

	function hello3(ExtWord $extWord) {
		// ...
	}
}


$myClass = new MyClass();

$myClass-&gt;hello(new Word());
$myClass-&gt;hello(new ExtWord());
&lt;/pre&gt;

Polad, if you still cannot copy the code correctly then shoot me an email at michaelnino.com and I&#039;d be glad to reply with code or chat!

Mike :-)</description>
		<content:encoded><![CDATA[<p>Dinke,</p>
<p>Please clean up blog entries. I posted some PHP code but it didn&#8217;t escape the content so greater than and less than signs for example are rendering the code for Polad incorrectly. Also, the blog posts an entry *before* you enter the captcha which defeats the purpose of having a captcha. Consequently, there are 2 almost identical blog posts&#8211; second one is correct.</p>
<p>Okay here is the code again&#8230;.</p>
<pre>
class Word {
	// ...
}

class ExtWord extends Word {
	// ...
}

class MyClass {

	// Method Signature Overloading (Polymorphism)
	function __call($method, $parameters) {
		foreach (get_class_methods(__CLASS__) as $class_method) {
			if (preg_match('/'.$method.'\d+/', $class_method)) {
				$reflect_method = new ReflectionMethod(__CLASS__, $class_method);
				if (count($parameters) == $reflect_method-&gt;getNumberOfParameters()) {
					$class_parameters = $reflect_method-&gt;getParameters();
					for ($p=0; $p&lt;count($parameters); $p++) {
						if (get_class($parameters[$p]) == $class_parameters[$p]-&gt;getClass()-&gt;getName()) {
							if ($p == count($parameters)-1) {
								call_user_func_array(array(&amp;$this, $class_method), $parameters);
								break 2; // Method Signature Match
							}
						} else {
							break;
						}
					}
				}
			}
		}
	}

	function hello2(Word $word) {
		// ...
	}

	function hello3(ExtWord $extWord) {
		// ...
	}
}

$myClass = new MyClass();

$myClass-&gt;hello(new Word());
$myClass-&gt;hello(new ExtWord());
</pre>
<p>Polad, if you still cannot copy the code correctly then shoot me an email at michaelnino.com and I&#8217;d be glad to reply with code or chat!</p>
<p>Mike :-)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

