[pmwiki-devel] Error suppression - best practice

Petko Yotov 5ko at 5ko.fr
Sun Mar 1 14:49:53 CST 2015


"Challanged pretty strongly" with what arguments and sources, citations 
or references?

Someone once challanged our use of apostrophes to wrap HTML attributes - 
which was extremely wrong, and we were amateurs, and we had to use 
double quotes instead. When I pointed to the W3C HTML and to the XHTML 
Transitional standards which allow the use of apostrophes, the person 
kept insisting that it was wrong. What can you reply to someone like 
this.

   http://php.net/manual/en/language.operators.errorcontrol.php

Using this @ operator is very consise and the code stays short, readable 
and maintainable. Consider:

   if ( @$foo ) { }
   @$bar++;

versus:

   if ( isset($foo) && $foo>'' ) { }
   if ( ! isset($bar) ) $bar = 1;
   else $bar++;

(for global variables you can also use the function IsEnabled().)

The use of the @ operator is somewhat slower than isset(), in my 
testings about 0.0000037 seconds per call (without bytecode compilation 
or memcache which would be much less). This is less than 4 microseconds. 
I'd trade these any day for more readable and maintainable code.

Petko

On 2015-03-01 20:47, Peter Bowers wrote:
> I see often in PmWiki core & recipes where errors are suppressed via @:
> 
> if (@$foo['bar'])...
> 
> Recently I was challenged pretty strongly that this was never a good
> practice.
> 
> So... is it just preference & this guy was opinionated? Or is this an 
> older
> way to do things & best practice is to not use this operator?




More information about the pmwiki-devel mailing list