Difference between empty ($ x) and @ $ x?

Is there any functional difference between if(!empty($x))and if(@$x)?

NB I know that @suppresses errors, and I do not use it lightly.

+4
source share
3 answers

There may not be a functional difference, as others have pointed out, but the use if(@$x)simply does not seem to be correct, and there is a reason why not use it.

From the documentation on the suppression error statement :

set_error_handler(), , ( ) error_reporting(), 0, , @.

- :

, @, :

  • , , , , @

  • . - , NONE.

  • @? 0 . , , 0

, -

, , , if(@$x) isset empty. , , .

+2

.

When $x="foo";

@$x == true
!empty($x) == true
isset($x) == true

When $x has not been set!

@$x == false
!empty($x) == false
isset($x) == false

x.

When $x=0;

@$x == false
!empty($x) == false
isset($x) == true

1.

When $x=1;

@$x == true
!empty($x) == true
isset($x) == true
+2

, , , .

:

var_dump(!empty($x));
var_dump(!!@$x);

$x is an empty array
boolean false
boolean false

$x is int(1)
boolean true
boolean true

$x is int(0)
boolean false
boolean false

$x is float(0.1)
boolean true
boolean true

$x is string(0)
boolean false
boolean false

$x is string(1)
boolean true
boolean true

$x is string(abc)
boolean true
boolean true

$x is instance of stdClass
boolean true
boolean true

$x is true
boolean true
boolean true

$x is false
boolean false
boolean false

$x is defined null
boolean false
boolean false

$x is not set
boolean false
boolean false
+1

All Articles