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 Previous  1, 2
 
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: Wed Jul 13, 2011 2:40 pm    Post subject: Reply with quote

mohrt wrote:
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?


Code:
<?php
function x() { }
 for ($i = 0; $i < 1000000; $i++) { x(); }
?>

 real    0m7.617s
 user    0m6.788s
 sys    0m0.792s

 vs

<?php
function x() { }
 for ($i = 0; $i < 1000000; $i++) { @x(); }
?>

 real    0m13.333s
 user    0m12.437s
 sys    0m0.836s


so for every @ it's 2 times slower...

globe wrote:
If I understood you correctly, you're running xdebug on a production machine.

nope... it's devel, don't worry

EDIT:
so anyway... there are probably some places where you could resign from @

for example this default compilermodifier... after all getVariable will always return variable or object "undefined smarty variable" putting aside this notice inside of this function... or am I wrong?


Last edited by bober10 on Wed Jul 13, 2011 2:47 pm; edited 1 time in total
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 2:44 pm    Post subject: Reply with quote

bober10 wrote:
so for every @ it's 2 times slower...


did you bench that on your dev machine? remember to disable xdebug (and the like) before benchmarking, as they screw up your results considerably.
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 2:48 pm    Post subject: Reply with quote

globe wrote:
bober10 wrote:
so for every @ it's 2 times slower...


did you bench that on your dev machine? remember to disable xdebug (and the like) before benchmarking, as they screw up your results considerably.


it's second comment from here:
http://php.net/manual/en/language.operators.errorcontrol.php
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 2:53 pm    Post subject: Reply with quote

Yes, globe is right. In general it's not a good idea for performace to have xdebug enabled on production servers.

I don't know which settings of xdebug you are using, but at least on my local test server it does not write @silent suppressed errors to the log files.
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 2:57 pm    Post subject: Reply with quote

According to the comments, the @ operator adds .005 or 5 thousandths to the operation, and that is only upon an actual error. Not completely insignificant, but not a show stopper. FYI eventually we will implement custom exception handling for all internal functions, and that should address this concern.
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 3:01 pm    Post subject: Reply with quote

mohrt wrote:
According to the comments, the @ operator adds .005 or 5 thousandths to the operation, and that is only upon an actual error. Not completely insignificant, but not a show stopper.


it ads 0.005 if there is no error!

Quote:
FYI eventually we will implement custom exception handling for all internal functions, and that should address this concern.
great... so what should i do to prevent this until there'll be error handling?
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 3:08 pm    Post subject: Reply with quote

Anyway we had internally a lot of discussions about the handling of unassigned variables. Depending on the usage of the variables we did run into a lot of compiler problems when trying to avoid @silent in a general way.

Currently we have no better solution.
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 3:12 pm    Post subject: Reply with quote

If you have an immediate concern, you can edit the source files and remove the @ for your installation, or adjust the code to your liking. It is open source, you can do whatever floats your boat. Let us know what you come up with.
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 3:39 pm    Post subject: Reply with quote

U.Tews wrote:
Anyway we had internally a lot of discussions about the handling of unassigned variables. Depending on the usage of the variables we did run into a lot of compiler problems when trying to avoid @silent in a general way.

Currently we have no better solution.


ok so about default compilermodifier... after all getVariable will always return variable or object "undefined smarty variable" putting aside this notice inside of this function... if that's the case why use @ there? did i miss some functions on the way
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 3:58 pm    Post subject: Reply with quote

Well the default modifier could be attached to more complex values like an array element, object properties, returned results of tags and others.
Code:
{$foo['bar']|default:''}{$foo->bar|default...}{myfunction()|default}


The result of getVariable() is just one of the possible cases.

I have checked also most common other engines. Nobody had a smarter idea as using @silent for cases like this.

We have some ideas for a default variable handler for Smarty 3.2 which may perhaps avoid some @silent cases. But this currently still in evaluation.
Back to top
View user's profile Send private message
bober10
Smarty Rookie


Joined: 12 Jul 2011
Posts: 13

PostPosted: Wed Jul 13, 2011 4:34 pm    Post subject: Reply with quote

U.Tews wrote:
Well the default modifier could be attached to more complex values like an array element, object properties, returned results of tags and others.
Code:
{$foo['bar']|default:''}{$foo->bar|default...}{myfunction()|default}


The result of getVariable() is just one of the possible cases.

I have checked also most common other engines. Nobody had a smarter idea as using @silent for cases like this.


i know one... smarty2 Razz one if one isset, that's all Wink

but anyway
if function is called...
if it exists
it will return null at default or anything passed to return
else
i want it to rise error so no @ please! (besides it will stop at compilling because there is no such function
fi

in case of an object or array getVariable is generated in any case so it does not matter
Code:
<?php echo (($tmp = @$_smarty_tpl->getVariable('foo',null,true,false)->value['bar'])===null||$tmp==='' ? '' : $tmp);?>
<?php echo (($tmp = @$_smarty_tpl->getVariable('foo',null,true,false)->value->bar)===null||$tmp==='' ? '' : $tmp);?>


so for this cases we do not need @ ...anything else?
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 4:51 pm    Post subject: Reply with quote

This is the compiled code of Smarty2 for {$foo|default:''}

Code:
<?php echo ((is_array($_tmp=@$this->_tpl_vars['foo'])) ? $this->_run_mod_handler('default', true, $_tmp, '') : smarty_modifier_default($_tmp, '')); ?>


So it does use @silent as well.

For undefined array elements it doe not help that geVariable returns the variable or null. You would get an undefined index notice. Same with undefined properties in objects.

Believe me we spend many days in trying ti find a solution which the compiler can handle in a general way. We did end up in an endless mess of problems to handle all these cases.
Back to top
View user's profile Send private message
bober10
Smarty Rookie


Joined: 12 Jul 2011
Posts: 13

PostPosted: Wed Jul 13, 2011 5:26 pm    Post subject: Reply with quote

U.Tews wrote:
So it does use @silent as well.


yes you're right...

then you have no other choice... you must fix missing variable in debug.tpl Smile
Back to top
View user's profile Send private message
Mahindra
Smarty Rookie


Joined: 25 Aug 2011
Posts: 6

PostPosted: Tue Oct 11, 2011 2:30 am    Post subject: 3 0 8 Undefined variable error when using default Reply with quote

New install of OpenCart.

In clicking the account link, i get this error: Notice: Undefined variable: text_register in /home/tinadcom/public_html/cart/catalog/view/theme/yoocart002/template/account/login.tpl on line 35

I know it must be a simple fix, so can anyone help me?

Thanks ahead of time
Back to top
View user's profile Send private message Send e-mail AIM Address
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 Previous  1, 2
Page 2 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