0

Can you please tell me the difference between $variable and @$variable in php

<?php
 curl function abc
{
 get information of url and return information string
}
$html=abc();
$doc=DOMDocument();
@$doc->LoadHTML($html); 
?>

here if we take normal variable it gives error why its so and whats the difference

PeeHaa
  • 66,697
  • 53
  • 182
  • 254

4 Answers4

3

A @ before a function call means "suppress warnings".

So, @$doc->LoadHTML($html); suppresses warnings from the method call (LoadHTML()).

In general this is a bad idea, because the warnings mean you are doing something wrong, and you would better fix that instead of playing deaf.

MightyPork
  • 16,661
  • 9
  • 66
  • 120
1

The @ operator tells the compiler to ignore the error that PHP could give, its advised not to use it.

George
  • 2,031
  • 4
  • 11
  • 15
1

Suppress warning when accessing that property, if for instance $html was undefined then no error is displayed, see http://davidwalsh.name/suppress-php-errors-warnings

ka_lin
  • 8,596
  • 5
  • 31
  • 50
0

@ is called Error Control Operator, it can be prepended before expression to disable error reporting for that expression.

Please see this post for more information: Suppress error with @ operator in PHP

Community
  • 1
  • 1
Jason OOO
  • 3,447
  • 2
  • 21
  • 28