<?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>UnixWars &#187; PHP</title>
	<atom:link href="http://unixwars.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://unixwars.com</link>
	<description>Taher Shihadeh's ragbag</description>
	<lastBuildDate>Mon, 26 Dec 2011 23:38:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>override_function() in PHP</title>
		<link>http://unixwars.com/2008/11/29/override_function-in-php/</link>
		<comments>http://unixwars.com/2008/11/29/override_function-in-php/#comments</comments>
		<pubDate>Fri, 28 Nov 2008 22:00:05 +0000</pubDate>
		<dc:creator>Taher Shihadeh</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://unixwars.com/?p=197</guid>
		<description><![CDATA[I&#8217;ve been writing a wrapper for Cherokee&#8217;s MySQL load balancer to transparently replace PHP&#8217;s MySQL functions and provide connection pooling and database balancing at absolutely no cost. And I encountered a problem wanting to override those built-in functions. It looks like the override_function() has a bug that prevents from using it to override two or [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been writing a wrapper for Cherokee&#8217;s <a href="http://www.cherokee-project.com/doc/cookbook_dbslayer.html">MySQL load balancer</a> to transparently replace PHP&#8217;s MySQL functions and provide connection pooling and database balancing at absolutely no cost. And I encountered a problem wanting to override those built-in functions.</p>
<p>It looks like the <a href="http://es.php.net/override_function">override_function()</a> has a <a href="http://pecl.php.net/bugs/bug.php?id=10208">bug</a> that prevents from using it to override two or more functions, since it issues this error:</p>
<pre class="prettyprint">Fatal error: Cannot redeclare __overridden__()</pre>
<p>Judging by the C code for PHP&#8217;s override_function() function, instead of hardcoding the overriden function name it was planed to generate random names, but for reasons unknown to me this never happened.</p>
<p>Anyway, I can&#8217;t believe the fix for this is so simple and yet the solution didn&#8217;t appear in PHP&#8217;s excellent <a href="http://es.php.net/docs.php">online documentation</a>. It had me lost for a while, but it&#8217;s as simple as renaming the overriden function!! This is from the wrapper I mentioned, that will be distributed with <a href="http://cherokee-project.com">Cherokee</a> shortly:</p>
<pre class="prettyprint">foreach ($substs as $func => $ren_func) {
    override_function($func, $args[$func], "return $substs[$func];");
    rename_function("__overridden__", $ren_func);
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://unixwars.com/2008/11/29/override_function-in-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

