Re: error_reporting E_ALL friendly Smarty_compiler
| From: | Monte Ohrt | Date: | Mon, 23 Apr 2001 18:33:36 +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-569@lists.php.net to get a copy of this message | ||
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/