View previous topic :: View next topic |
Author |
Message |
bober10 Smarty Rookie
Joined: 12 Jul 2011 Posts: 13
|
Posted: Wed Jul 13, 2011 2:40 pm Post subject: |
|
|
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 |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Wed Jul 13, 2011 2:44 pm Post subject: |
|
|
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 |
|
bober10 Smarty Rookie
Joined: 12 Jul 2011 Posts: 13
|
Posted: Wed Jul 13, 2011 2:48 pm Post subject: |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Jul 13, 2011 2:53 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Jul 13, 2011 2:57 pm Post subject: |
|
|
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 |
|
bober10 Smarty Rookie
Joined: 12 Jul 2011 Posts: 13
|
Posted: Wed Jul 13, 2011 3:01 pm Post subject: |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Jul 13, 2011 3:08 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Jul 13, 2011 3:12 pm Post subject: |
|
|
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 |
|
bober10 Smarty Rookie
Joined: 12 Jul 2011 Posts: 13
|
Posted: Wed Jul 13, 2011 3:39 pm Post subject: |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Jul 13, 2011 3:58 pm Post subject: |
|
|
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 |
|
bober10 Smarty Rookie
Joined: 12 Jul 2011 Posts: 13
|
Posted: Wed Jul 13, 2011 4:34 pm Post subject: |
|
|
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 one if one isset, that's all
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Jul 13, 2011 4:51 pm Post subject: |
|
|
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 |
|
bober10 Smarty Rookie
Joined: 12 Jul 2011 Posts: 13
|
Posted: Wed Jul 13, 2011 5:26 pm Post subject: |
|
|
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 |
|
Back to top |
|
Mahindra Smarty Rookie
Joined: 25 Aug 2011 Posts: 6
|
Posted: Tue Oct 11, 2011 2:30 am Post subject: 3 0 8 Undefined variable error when using default |
|
|
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 |
|
|