Re: E_RECOVERABLE_ERROR - 5.1.6 to 5.2.0

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Roman Neuhauser wrote:
> # jochem@xxxxxxxxxxxxx / 2007-01-02 21:23:02 +0100:
>> David CHANIAL wrote:
>>> We are preparing the upgrade of PHP for our customers, but, after some tests, 
>>> we have a migration "problem" caused by the news E_RECOVERABLE_ERROR.
>>>
>>> So, even if the upgrade guide (http://www.php.net/UPDATE_5_2.txt) talk about 
>>> the method to handle this new errors (by using try/catch), they don't talk 
>> there is no mention of try/catch - it seems that the rather unfortunate word
>> 'catchable' was used to describe the act of setting up a user defined error handler
>> (see: http://php.net/manual/en/function.set-error-handler.php) to handle errors
>> that are triggered by the php core. [errors != exceptions]
> 
> Unfortunately. Consider this:
> 
>     function f($any)
>     {
>         printf("%s\n", $any);
>     }
> 
> Innocent enough? It's an E_RECOVERABLE_ERROR if $any is an object
> without __toString().

It's also an example of a former C coder's understanding of how to do
things in PHP.  Not only is this extremely inefficient (a function call
is significant overhead in PHP) it is doubly inefficient through the
unnecessary use of printf().  printf() is best used when you are
modifying the display of the output, the %s modifier by itself is
pointless in PHP.

function f($any)
{
    echo $any . "\n";
}

This has no E_RECOVERABLE_ERROR possibility and is far more efficient.
Better yet, replace

f($blah)

with

echo $blah . "\n"

This is a good example of how the flexibility of PHP can bite you, but
is also a good example of how bad coding adds both complexity and
inefficiency to the resulting software.  If f() is called often, there
might be a noticeable speedup if it were replaced.  I once had a complex
database ORM-HTML mapping app that was about 10% faster when I replaced
all the "" strings with '' strings.  This was on a slow machine with an
early PHP, but little things like this can be very important.

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux