Re: error_reporting E_ALL friendly Smarty_compiler
| From: | Cynic | Date: | Mon, 23 Apr 2001 19:10:05 +0000 |
| Subject: | Re: error_reporting E_ALL friendly Smarty_compiler | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-573@lists.php.net to get a copy of this message | ||
I think Andrei might answer this question: is an explicit
isset() check more costly than a notice inhibited by '@' or
by lowering the error_reporting level? I mean, what are the
internals?
As far as I'm concerned, I write all my PHP programs to work
in error_reporting E_ALL since it's an invaluable debugging
tool (barring a real debugger) that actually speeds up the
progress of my work, and once written this way, the scripts may
as well be used in production with this setting.
If I wanted to write a program (that would use Smarty) with
E_ALL, I'd have to send the error messages to a log, which
isn't as convenient as having them immediatelly on the screen,
PLUS I'd have to look for relevant warnings among the 100+
warnings produced by Smarty. Again, not exactly very convenient.
IOW, if I want to use Smarty in any of my applications, it's
got to be E_ALL-friendly.
At 20:33 23.4. 2001, Monte Ohrt wrote the following:
--------------------------------------------------------------
>This brings up an interesting topic :-) I sometimes go around and fix
>compiler warnings on unset variables and similar types of things.
>Although you would initially think that "perfect" code would not
>generate warning messages, there is also an overhead to checking for all
>these little things. Each time you fix a warning, you are usually adding
>more complexity to the code. Writing in C is obvious, you would want to
>get all this cleaned up. But in scripting languages such as PHP, many of
>these details are automatically taken care of by the parser such as
>memory management, variable initialization, etc. I would think in PHP,
>turning on E_NOTICE would purely be for debugging or curiosity, not for
>a production environment.
>
>Any other thoughts on this?
>
>Monte
>
>Cynic wrote:
>>
>> The included patch makes Smarty_compiler, and the compiled
>> templates, work without a warning with error_reporting set to
>> E_ALL. (Tested with the default index.tpl.)
>>
>> The original class relied on E_ALL &~ E_NOTICE:
>>
>> First, there were couple of list($foo, $bar) = $array lines
>> where $bar wasn't always set. I could have just prepended the
>> statements with @, but I don't like that approach. An example:
>>
>> - list($var_ref, $modifiers) = explode('|', $section_prop_expr, 2);
>> + $section_prop_expr = explode('|', $section_prop_expr, 2);
>> + $var_ref = $section_prop_expr[0];
>> + if (isset($section_prop_expr[1])) {
>> + $modifiers = $section_prop_expr[1];
>> + } else {
>> + $modifiers = '' ;
>> + }
>>
>> Second, _compile_files() emitted warnings if $text_blocks[$curr_tb]
>> wasn't set. I added a simple isset() before the preg_match_all() call.
>>
>> Third, the compiled templates relied on E_ALL &~ E_NOTICE in the
>> config-setting code. I added two isset()s, and an explicit declaration
>> of $_smarty_config.
>>
>> There's probably more that needs patching, but at least the default
>> index.tpl now compiles, and index.tpl.php runs, without a notice.
>>
>> I know this patch is somewhat lengthy, but it's easy to review.
>> If you want me to break it into a set of isolated patches, let me know.
>>
>> Oh, BTW, is there actually any interest in making Smarty
>> error_reporting E_ALL - friendly?
>>
>> cynic@mail.cz
>> -------------
>> And the eyes of them both were opened and they saw that their files
>> were world readable and writable, so they chmoded 600 their files.
>> - Book of Installation chapt 3 sec 7
>>
>> ------------------------------------------------------------------------
>>
>> smarty_compiler.class.diff.phpName: smarty_compiler.class.diff.php
>> Type: Plain Text (text/plain)
>>
>> ------------------------------------------------------------------------
>> ---
>> You are currently subscribed to smarty as: monte@ispi.net
>> To unsubscribe send a blank email to $subst('Email.Unsub')
>> Visit Smarty's homepage at
>> http://www.phpinsider.com/php/code/Smarty/
>
>--
>Monte Ohrt <monte@ispi.net>
>http://www.ispi.net/
------end of quote------
cynic@mail.cz
-------------
And the eyes of them both were opened and they saw that their files
were world readable and writable, so they chmoded 600 their files.
- Book of Installation chapt 3 sec 7