5 ms·
@operator is much faster in 5.4.x $x = @$f["x"] is right place to use it. $x = @custom_func() - is a disaster, do not do it
by parf73 14y ago
@operator is much faster in 5.4.x
$x = @$f["x"] is right place to use it.
$x = @custom_func() - is a disaster, do not do it
- neurotech1 14y agoso what is wrong with; if(function_exists(custom_func) { $x = @custom_func(); } if((!isset($x)) || (empty($x))) { echo('Custom Error'); } else { //Do the work } This may be considered verbose, but can be useful if custom or "sometimes" installed libraries are involved
- jtreminio 14y ago> if(function_exists(custom_func) { $x = @custom_func(); } http://php.net/manual/en/function.call-user-func.php http://php.net/manual/en/function.call-user-func.php Why would you prepend @ to your function call? > if((!isset($x)) || (empty($x))) { echo('Custom Error'); } else { //Do the work } You're duplicating your efforts. empty() takes into account if a variable or key has been initialized, and also if it has a non-false value. isset() only checks if the variable/key has been intialized and nothing else.
- jtreminio 14y ago> $x = @$f["x"] is right place to use it. No, it's not. There's built-in methods for that: isset() and empty().
- narcissus 14y agoOr array_key_exists(), depending on exactly what you're hoping for :(
- pavel_lishin 14y agoempty() is not a good idea. What if $f["x"] is an empty string ""? Or 0, or 0.0, or "0", or any of the other values for which it returns true?
- jtreminio 14y agoIt completely depends on the use case. My point was, don't use @