Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

3.0.8 Undefined variable error when using default
Goto page 1, 2  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
bober10
Smarty Rookie


Joined: 12 Jul 2011
Posts: 13

PostPosted: Tue Jul 12, 2011 7:09 pm    Post subject: 3.0.8 Undefined variable error when using default Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Jul 12, 2011 8:31 pm    Post subject: Reply with quote

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
View user's profile Send private message
bober10
Smarty Rookie


Joined: 12 Jul 2011
Posts: 13

PostPosted: Tue Jul 12, 2011 9:07 pm    Post subject: Reply with quote

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
View user's profile Send private message
bober10
Smarty Rookie


Joined: 12 Jul 2011
Posts: 13

PostPosted: Wed Jul 13, 2011 11:36 am    Post subject: Reply with quote

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
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Wed Jul 13, 2011 11:52 am    Post subject: Reply with quote

This is a compiler issue Uwe will have a look into.
Back to top
View user's profile Send private message Visit poster's website
bober10
Smarty Rookie


Joined: 12 Jul 2011
Posts: 13

PostPosted: Wed Jul 13, 2011 12:21 pm    Post subject: Reply with quote

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... Wink

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Wed Jul 13, 2011 12:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
bober10
Smarty Rookie


Joined: 12 Jul 2011
Posts: 13

PostPosted: Wed Jul 13, 2011 12:24 pm    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Wed Jul 13, 2011 12:35 pm    Post subject: Reply with quote

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
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Wed Jul 13, 2011 12:39 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
bober10
Smarty Rookie


Joined: 12 Jul 2011
Posts: 13

PostPosted: Wed Jul 13, 2011 12:39 pm    Post subject: Reply with quote

i do use xdebug

but level is not what annoys me...the fact that error apears is Wink

EDIT:
BTW. this is not stopping my application... it just spam logs...
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Wed Jul 13, 2011 12:45 pm    Post subject: Reply with quote

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
View user's profile Send private message
bober10
Smarty Rookie


Joined: 12 Jul 2011
Posts: 13

PostPosted: Wed Jul 13, 2011 12:55 pm    Post subject: Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Jul 13, 2011 1:35 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Wed Jul 13, 2011 1:55 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty 3 All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP