View previous topic :: View next topic |
Author |
Message |
bober10 Smarty Rookie
Joined: 12 Jul 2011 Posts: 13
|
Posted: Tue Jul 12, 2011 7:09 pm Post subject: 3.0.8 Undefined variable error when using default |
|
|
I'm trying to upgrade from smarty 2 and I'm getting a lot of undefined variables everyware where i'm using default
I'm guessing that someone already found solution for this... could you point me to the solution, please?
EDIT:
the problem is that modifiercompiler.default.php uses @ to downgrade warning undefined variable to notice and it throws notice everytime you use default modifier
and @ sucks :/ |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Jul 12, 2011 8:31 pm Post subject: |
|
|
Smarty2 did always suppress E_NOTICE messages during template processing.
For same behaviour in Smarty3 use
$smarty->error_reporting = error_reporting() & ~E_NOTICE;
or use the 'default' modifier at variables you expect to be undefined.
See also the README file. |
|
Back to top |
|
bober10 Smarty Rookie
Joined: 12 Jul 2011 Posts: 13
|
Posted: Tue Jul 12, 2011 9:07 pm Post subject: |
|
|
U.Tews wrote: |
$smarty->error_reporting = error_reporting() & ~E_NOTICE;
|
i'm suppressing notices in this exact way
my problem is that smarty2 used isset in default modifier, in smarty3 it does not and that causes warning |
|
Back to top |
|
bober10 Smarty Rookie
Joined: 12 Jul 2011 Posts: 13
|
Posted: Wed Jul 13, 2011 11:36 am Post subject: |
|
|
a little bump...
so... in debug.tpl there is a line:
Code: | {$id = $template_name|default:''|md5} |
this line is compilled into this:
Code: | <?php $_smarty_tpl->tpl_vars['id'] = new Smarty_variable(smarty_modifier_md5((($tmp = @$_smarty_tpl->getVariable('template_name')->value)===null||$tmp==='' ? '' : $tmp)), null, null);?> |
the thing is that when i use default modifier i'd like it not throw an notice but Undefined_Smarty_Variable, so $_smarty_tpl->getVariable('template_name') should become something like Code: | $_smarty_tpl->getVariable('template_name',null,true,FALSE) |
the thing is that it should happen like that only when using default, and here i'm lost...
How to do it? |
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Wed Jul 13, 2011 11:52 am Post subject: |
|
|
This is a compiler issue Uwe will have a look into. |
|
Back to top |
|
bober10 Smarty Rookie
Joined: 12 Jul 2011 Posts: 13
|
Posted: Wed Jul 13, 2011 12:21 pm Post subject: |
|
|
i don't know...
maybe it's just a problem of using unsigned variable in debug.tpl
after all it's a thing that started to annoy me appearing in my application logs...
and besides that compiler recives desired object... warning is raised in smarty_internal_data.php just before sending this object.
Last edited by bober10 on Wed Jul 13, 2011 12:22 pm; edited 1 time in total |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Jul 13, 2011 12:21 pm Post subject: |
|
|
Code: | <?php $_smarty_tpl->tpl_vars['id'] = new Smarty_variable(smarty_modifier_md5((($tmp = @$_smarty_tpl->getVariable('template_name')->value)===null||$tmp==='' ? '' : $tmp)), null, null);?> |
Because of the @ error supression $_smarty_tpl->getVariable('template_name')->value should never drop a notice when template_name is undefined.
Do you really get it on your system? |
|
Back to top |
|
bober10 Smarty Rookie
Joined: 12 Jul 2011 Posts: 13
|
Posted: Wed Jul 13, 2011 12:24 pm Post subject: |
|
|
U.Tews wrote: |
Because of the @ error supression $_smarty_tpl->getVariable('template_name')->value should never drop a notice when template_name is undefined.
Do you really get it on your system? | Unsigned variable is originaly at warning level... |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Jul 13, 2011 12:35 pm Post subject: |
|
|
An unassigned variable dores drop an E_NOTICE. But because of the @ you should get nothing.
This does work in all other places....
Or did you use some sort of custom error handler? |
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Wed Jul 13, 2011 12:39 pm Post subject: |
|
|
bober10 wrote: | Unsigned variable is originaly at warning level... |
Don't think so, as <?php echo $bar; ?> outputs »PHP Notice: Undefined variable: bar«
You should also note that using your own error handler (http://php.net/set_error_handler) may break the @silence operator if it wasn't designed properly: https://gist.github.com/1080214
If you see warnings/notices where there shouldn't be any, I bet a custom error handler is in play… |
|
Back to top |
|
bober10 Smarty Rookie
Joined: 12 Jul 2011 Posts: 13
|
Posted: Wed Jul 13, 2011 12:39 pm Post subject: |
|
|
i do use xdebug
but level is not what annoys me...the fact that error apears is
EDIT:
BTW. this is not stopping my application... it just spam logs... |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Jul 13, 2011 12:45 pm Post subject: |
|
|
I know that when you are debugging code xdebug does catch also the @ supressed messages with the option to continue. But this does not happen during normal execution. |
|
Back to top |
|
bober10 Smarty Rookie
Joined: 12 Jul 2011 Posts: 13
|
Posted: Wed Jul 13, 2011 12:55 pm Post subject: |
|
|
ok... even so... I'm not sure about it, but are you saying that i should ignore error suppresing even if it significantly slows down whole application? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Jul 13, 2011 1:35 pm Post subject: |
|
|
bober10 wrote: | ok... even so... I'm not sure about it, but are you saying that i should ignore error suppresing even if it significantly slows down whole application? |
Can you show a benchmark that shows the significance? What are we talking, a thousandths of a second, if that? |
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Wed Jul 13, 2011 1:55 pm Post subject: |
|
|
bober10 wrote: | ok... even so... I'm not sure about it, but are you saying that i should ignore error suppresing even if it significantly slows down whole application? |
If I understood you correctly, you're running xdebug on a production machine. If that is true, @silence is the very least of your worries. |
|
Back to top |
|
|