davidbaumann
davidbaumann

Reputation: 218

PHP - disable warning for single line

I have a plugin in my forum which throws a warning.
I want to fix the problem, but firstly, I want to hide the warning message to the users.

I know I can change it globally, but I just want to do it for some lines.

How can I do this?

$bbcode_parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());

gives the error:

Warnung: Assigning the return value of new by reference is deprecated in ..../includes/garage_func_var.php (Zeile 6411)

I already know I need to use @ but where do I put this?

Upvotes: 6

Views: 7360

Answers (2)

Mike Q
Mike Q

Reputation: 7327

Use @ only as an absolute last resort. It is considered bad coding to use @ as slows things down and moreover creates headaches for programmers (including yourself) in the future when trying to debug. This is really frowned upon.

You should:

Hide warnings only for that call using a function using set_ini

Use "try" in php to manage errors.

Upvotes: 0

Markandeya
Markandeya

Reputation: 537

@ can be used to suppress warnings, notices and errors.

Fatal errors are displayed in PHP 7 which breaks the script.

@ can be used before variables, functions, include calls, constants and so forth but cannot be prepended to function or class definitions, conditionals, loops and so forth.
So for example, to hide an undefined property error:

Class Cars{
}
$obj = new Cars();
echo @$obj->idontexist;

As to your specific problem:

@$bbcode_parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());

should fix it.

While the mentioned deprecated warning message is displayed in PHP 5, the following will be displayed in PHP 7 since it was deprecated in the upgrade.

PHP 7 Note:

Parse error: syntax error, unexpected 'new' (T_NEW)

Upvotes: 10

Related Questions