<?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: Exceptional PHP</title>
	<atom:link href="http://www.procata.com/blog/archives/2004/05/24/exceptional-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.procata.com/blog/archives/2004/05/24/exceptional-php/</link>
	<description>PHP Programming, Web Development, PHP Advocacy and PHP Best Practices.</description>
	<lastBuildDate>Thu, 02 Sep 2010 05:14:22 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Zend Framework Webcast &#124; Professional PHP</title>
		<link>http://www.procata.com/blog/archives/2004/05/24/exceptional-php/#comment-12968</link>
		<dc:creator>Zend Framework Webcast &#124; Professional PHP</dc:creator>
		<pubDate>Mon, 05 Dec 2005 20:45:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.procata.com/blog/archives/2004/05/24/exceptional-php/#comment-12968</guid>
		<description>[...] The coding standards emphasize not reserving global resources. The framework will not define functions or global constants, it uses exceptions and doesn&#039;t reserve __autoload for its own use. This is very good. On the other hand, it seems to rely on static methods quite a bit, which I think can burn you over the long run if you are trying to offer a componentized architecture and can make code more difficult to test. I&#039;ve been moving away from static methods as much as I can in my own code. Eventually, I always seem to regret using them. They lure you in at the beginning with the promise of simplicity and then they punish you later with their inflexibility. [...]</description>
		<content:encoded><![CDATA[<p>[...] The coding standards emphasize not reserving global resources. The framework will not define functions or global constants, it uses exceptions and doesn&#8217;t reserve __autoload for its own use. This is very good. On the other hand, it seems to rely on static methods quite a bit, which I think can burn you over the long run if you are trying to offer a componentized architecture and can make code more difficult to test. I&#8217;ve been moving away from static methods as much as I can in my own code. Eventually, I always seem to regret using them. They lure you in at the beginning with the promise of simplicity and then they punish you later with their inflexibility. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://www.procata.com/blog/archives/2004/05/24/exceptional-php/#comment-10498</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Fri, 26 Aug 2005 08:37:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.procata.com/blog/archives/2004/05/24/exceptional-php/#comment-10498</guid>
		<description>Could you please send to me the contacts of developer of your site? It looks so damn good!</description>
		<content:encoded><![CDATA[<p>Could you please send to me the contacts of developer of your site? It looks so damn good!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cavorite</title>
		<link>http://www.procata.com/blog/archives/2004/05/24/exceptional-php/#comment-76</link>
		<dc:creator>cavorite</dc:creator>
		<pubDate>Sun, 20 Jun 2004 13:02:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.procata.com/blog/archives/2004/05/24/exceptional-php/#comment-76</guid>
		<description>&lt;strong&gt;Breves y tacañas&lt;/strong&gt;
Nuevamente, un post escrito con poco tiempo: XML en PHP 5 . Una presentaci&#243;n sobre el infinito mundo de los acr&#243;nimos: PHP, XML, XSLT, DOM, SAX&#8230; Excepciones en PHP 5: &#191;Ser&#225;n un problema excepcional?, Otro post en el qu...</description>
		<content:encoded><![CDATA[<p><strong>Breves y tacañas</strong><br />
Nuevamente, un post escrito con poco tiempo: XML en PHP 5 . Una presentaci&oacute;n sobre el infinito mundo de los acr&oacute;nimos: PHP, XML, XSLT, DOM, SAX&#8230; Excepciones en PHP 5: &iquest;Ser&aacute;n un problema excepcional?, Otro post en el qu&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lukas</title>
		<link>http://www.procata.com/blog/archives/2004/05/24/exceptional-php/#comment-72</link>
		<dc:creator>Lukas</dc:creator>
		<pubDate>Fri, 18 Jun 2004 09:56:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.procata.com/blog/archives/2004/05/24/exceptional-php/#comment-72</guid>
		<description>Harry I really like your definition. I agree that exceptions make perfect sense for enviornment errors but not for syntactical or semantical errors. User errors shouldnt be exceptions as they incorrect input should be expected behaviour and if any they would be syntactical mistakes.</description>
		<content:encoded><![CDATA[<p>Harry I really like your definition. I agree that exceptions make perfect sense for enviornment errors but not for syntactical or semantical errors. User errors shouldnt be exceptions as they incorrect input should be expected behaviour and if any they would be syntactical mistakes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Smoking toooo much PHP</title>
		<link>http://www.procata.com/blog/archives/2004/05/24/exceptional-php/#comment-71</link>
		<dc:creator>Smoking toooo much PHP</dc:creator>
		<pubDate>Fri, 18 Jun 2004 01:27:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.procata.com/blog/archives/2004/05/24/exceptional-php/#comment-71</guid>
		<description>&lt;strong&gt;could PHP5 be an exceptional mess?&lt;/strong&gt;

PEAR dev is hot with the exception fever at present, The OO purists are beating down the door requesting the eviction of that horible legacy of a bygone age, PEAR_Error. And hoisting the flag of the Exception god at the gates.Well, It&#039;s not </description>
		<content:encoded><![CDATA[<p><strong>could PHP5 be an exceptional mess?</strong></p>
<p>PEAR dev is hot with the exception fever at present, The OO purists are beating down the door requesting the eviction of that horible legacy of a bygone age, PEAR_Error. And hoisting the flag of the Exception god at the gates.Well, It&#8217;s not</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Smoking toooo much PHP</title>
		<link>http://www.procata.com/blog/archives/2004/05/24/exceptional-php/#comment-70</link>
		<dc:creator>Smoking toooo much PHP</dc:creator>
		<pubDate>Fri, 18 Jun 2004 01:14:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.procata.com/blog/archives/2004/05/24/exceptional-php/#comment-70</guid>
		<description>&lt;strong&gt;could PHP5 be an exceptional mess?&lt;/strong&gt;

PEAR dev is hot with the exception fever at present, The OO purists are beating down the door requesting the eviction of that horible legacy of a bygone age, PEAR_Error. And hoisting the flag of the Exception god at the gates.Well, It&#039;s not </description>
		<content:encoded><![CDATA[<p><strong>could PHP5 be an exceptional mess?</strong></p>
<p>PEAR dev is hot with the exception fever at present, The OO purists are beating down the door requesting the eviction of that horible legacy of a bygone age, PEAR_Error. And hoisting the flag of the Exception god at the gates.Well, It&#8217;s not</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Smoking toooo much PHP</title>
		<link>http://www.procata.com/blog/archives/2004/05/24/exceptional-php/#comment-69</link>
		<dc:creator>Smoking toooo much PHP</dc:creator>
		<pubDate>Fri, 18 Jun 2004 01:14:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.procata.com/blog/archives/2004/05/24/exceptional-php/#comment-69</guid>
		<description>&lt;strong&gt;could PHP5 be an exceptional mess?&lt;/strong&gt;

PEAR dev is hot with the exception fever at present, The OO purists are beating down the door requesting the eviction of that horible legacy of a bygone age, PEAR_Error. And hoisting the flag of the Exception god at the gates.Well, It&#039;s not </description>
		<content:encoded><![CDATA[<p><strong>could PHP5 be an exceptional mess?</strong></p>
<p>PEAR dev is hot with the exception fever at present, The OO purists are beating down the door requesting the eviction of that horible legacy of a bygone age, PEAR_Error. And hoisting the flag of the Exception god at the gates.Well, It&#8217;s not</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Smoking toooo much PHP</title>
		<link>http://www.procata.com/blog/archives/2004/05/24/exceptional-php/#comment-68</link>
		<dc:creator>Smoking toooo much PHP</dc:creator>
		<pubDate>Fri, 18 Jun 2004 00:32:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.procata.com/blog/archives/2004/05/24/exceptional-php/#comment-68</guid>
		<description>&lt;strong&gt;could PHP5 be an exceptional mess?&lt;/strong&gt;

PEAR dev is hot with the exception fever at present, The OO purists are beating down the door requesting the eviction of that horible legacy of a bygone age, PEAR_Error. And hoisting the flag of the Exception god at the gates.Well, It&#039;s not </description>
		<content:encoded><![CDATA[<p><strong>could PHP5 be an exceptional mess?</strong></p>
<p>PEAR dev is hot with the exception fever at present, The OO purists are beating down the door requesting the eviction of that horible legacy of a bygone age, PEAR_Error. And hoisting the flag of the Exception god at the gates.Well, It&#8217;s not</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Smoking toooo much PHP</title>
		<link>http://www.procata.com/blog/archives/2004/05/24/exceptional-php/#comment-67</link>
		<dc:creator>Smoking toooo much PHP</dc:creator>
		<pubDate>Fri, 18 Jun 2004 00:30:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.procata.com/blog/archives/2004/05/24/exceptional-php/#comment-67</guid>
		<description>&lt;strong&gt;could PHP5 be an exceptional mess?&lt;/strong&gt;

PEAR dev is hot with the exception fever at present, The OO purists are beating down the door requesting the eviction of that horible legacy of a bygone age, PEAR_Error. And hoisting the flag of the Exception god at the gates.Well, It&#039;s not </description>
		<content:encoded><![CDATA[<p><strong>could PHP5 be an exceptional mess?</strong></p>
<p>PEAR dev is hot with the exception fever at present, The OO purists are beating down the door requesting the eviction of that horible legacy of a bygone age, PEAR_Error. And hoisting the flag of the Exception god at the gates.Well, It&#8217;s not</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harry Fuecks</title>
		<link>http://www.procata.com/blog/archives/2004/05/24/exceptional-php/#comment-29</link>
		<dc:creator>Harry Fuecks</dc:creator>
		<pubDate>Tue, 25 May 2004 07:04:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.procata.com/blog/archives/2004/05/24/exceptional-php/#comment-29</guid>
		<description>One thing that bothers me on the subject of exceptions in PHP is I&#039;ve yet to see anyone in PEAR approach the subject of a standard exceptions. Most languages using exceptions (including Java, Python and Javascript) provide a standard set of exception classes for common issues &lt;a href=&quot;http://docs.python.org/lib/module-exceptions.html&quot;&gt;such as these&lt;/a&gt;. This is a great opportunity for PEAR to make itself both invaluable to PHP and right some of the error handling wrongs it&#039;s done in the past.

Think the big plus of exceptions is it provides a standard mechanism everyone can use - the big issue with PHP4 is everyone&#039;s got a different approach and glueing them together, when using different libraries, is often painful. Some people are saying exceptions are slower compared to other flow control structures - haven&#039;t confirmed this for myself but my guess is while it may be true at first glance, it&#039;s not so true when writing real code e.g.

&lt;code&gt;
$result = someFunc();

switch ( $result ) {
    case ERROR_X:
        // Do something
    break;
    case ERROR_Y:
        // Do something
    break;
    case ERROR_Z:
        // Do something
    break;
    default:
        // Do the stuff that happens when there are no errors
    break;
}
&lt;/code&gt;

The cost of evaluating each condition in the switch is incurred every time it&#039;s used while the alternative;

&lt;code&gt;
try {
   $result = someFunc();
   // Do the stuff that happens when there are no errors
} catch (Error_X e) {

} catch (Error_Y e) {

} catch (Error_Z e) {

}
&lt;/code&gt;

Leaves evaluation of the type of error to only those cases where an error actually occurs (which is hopefully rare).

Personally what I&#039;d like to see is the possibility of being able to trap old style errors in a try catch block (but if you don&#039;t use one, the error propogates to the traditional global error handler). Would allow for code like;

&lt;code&gt;
try {
    $result = eval($someCode);
} catch (e) {

}
&lt;/code&gt;

Javascript does a very good job of this - you can even hard code syntax errors and catch them as exceptions. That&#039;s not to say this is the way applications should be designed but there are circumstances where it&#039;s useful and it implies a well implemented exception mechanism. I get the feeling we&#039;re going to end up with a mess in PHP between the old mechanism and the new exceptions.

Would be interesting to discuss error handling strategy in &quot;userland&quot; PHP. Think in helps to consider what type of error we&#039;re having to deal with. Based on the definitions I came up with &lt;a href=&quot;http://www.sitepoint.com/article/php-anthology-1-1-php-basics/4&quot;&gt;here&lt;/a&gt; some random thoughts;

- Syntax errors: use the old mechanism (programmers will want to fix these immediately) but allow exceptions for special cases like eval() and create_function()

- Semantic Errors: should mainly use the old mechanism (some will be a programmers mistake and something they want to fix) but perhaps exceptions for usage errors (e.g. divide by zero). At the same time if proper validation is being performed, the zero should never get to the function that might divide by it.

- Environment errors: this is where exceptions have something significant to error and should be the mechanism of choice, at least for libraries. Can&#039;t connect to the database, open a file or whatever - throw an exception.

A forth type of error might be &quot;User Errors&quot; but these are question of validation IMO.</description>
		<content:encoded><![CDATA[<p>One thing that bothers me on the subject of exceptions in PHP is I&#8217;ve yet to see anyone in PEAR approach the subject of a standard exceptions. Most languages using exceptions (including Java, Python and Javascript) provide a standard set of exception classes for common issues <a href="http://docs.python.org/lib/module-exceptions.html">such as these</a>. This is a great opportunity for PEAR to make itself both invaluable to PHP and right some of the error handling wrongs it&#8217;s done in the past.</p>
<p>Think the big plus of exceptions is it provides a standard mechanism everyone can use &#8211; the big issue with PHP4 is everyone&#8217;s got a different approach and glueing them together, when using different libraries, is often painful. Some people are saying exceptions are slower compared to other flow control structures &#8211; haven&#8217;t confirmed this for myself but my guess is while it may be true at first glance, it&#8217;s not so true when writing real code e.g.</p>
<p><code><br />
$result = someFunc();</p>
<p>switch ( $result ) {<br />
    case ERROR_X:<br />
        // Do something<br />
    break;<br />
    case ERROR_Y:<br />
        // Do something<br />
    break;<br />
    case ERROR_Z:<br />
        // Do something<br />
    break;<br />
    default:<br />
        // Do the stuff that happens when there are no errors<br />
    break;<br />
}<br />
</code></p>
<p>The cost of evaluating each condition in the switch is incurred every time it&#8217;s used while the alternative;</p>
<p><code><br />
try {<br />
   $result = someFunc();<br />
   // Do the stuff that happens when there are no errors<br />
} catch (Error_X e) {</p>
<p>} catch (Error_Y e) {</p>
<p>} catch (Error_Z e) {</p>
<p>}<br />
</code></p>
<p>Leaves evaluation of the type of error to only those cases where an error actually occurs (which is hopefully rare).</p>
<p>Personally what I&#8217;d like to see is the possibility of being able to trap old style errors in a try catch block (but if you don&#8217;t use one, the error propogates to the traditional global error handler). Would allow for code like;</p>
<p><code><br />
try {<br />
    $result = eval($someCode);<br />
} catch (e) {</p>
<p>}<br />
</code></p>
<p>Javascript does a very good job of this &#8211; you can even hard code syntax errors and catch them as exceptions. That&#8217;s not to say this is the way applications should be designed but there are circumstances where it&#8217;s useful and it implies a well implemented exception mechanism. I get the feeling we&#8217;re going to end up with a mess in PHP between the old mechanism and the new exceptions.</p>
<p>Would be interesting to discuss error handling strategy in &#8220;userland&#8221; PHP. Think in helps to consider what type of error we&#8217;re having to deal with. Based on the definitions I came up with <a href="http://www.sitepoint.com/article/php-anthology-1-1-php-basics/4">here</a> some random thoughts;</p>
<p>- Syntax errors: use the old mechanism (programmers will want to fix these immediately) but allow exceptions for special cases like eval() and create_function()</p>
<p>- Semantic Errors: should mainly use the old mechanism (some will be a programmers mistake and something they want to fix) but perhaps exceptions for usage errors (e.g. divide by zero). At the same time if proper validation is being performed, the zero should never get to the function that might divide by it.</p>
<p>- Environment errors: this is where exceptions have something significant to error and should be the mechanism of choice, at least for libraries. Can&#8217;t connect to the database, open a file or whatever &#8211; throw an exception.</p>
<p>A forth type of error might be &#8220;User Errors&#8221; but these are question of validation IMO.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
