johnvantes
johnvantes

Reputation: 39

PHP script still terminated even with @ operator

I am currently running a script that is failing to work, it turns out that there is this line:

$this->conn_id = @ftp_connect($this->ftp_server);

This line throw ftp_connect function undefined, but as it's preceded by @ operator, shouldn't it not terminated?

Anyway I checked there is error_reporting(E_ALL); in the beginning of the script. Is this the cause?

Thanks!

Upvotes: 0

Views: 74

Answers (2)

Toby Allen
Toby Allen

Reputation: 11213

As previous answers has specified @ doesnt work to suppress error when a function doesnt exits, however

if (function_exists('ftp_connect')){
        $this->conn_id = ftp_connect($this->ftp_server);
 }

will do the trick

Upvotes: 1

ScaisEdge
ScaisEdge

Reputation: 133360

Like in php doc http://php.net/manual/en/function.error-reporting.php

The @-operator works only on expressions. A simple rule of thumb is: if you can take the value of something, you can prepend the @ operator to it. For instance, you can prepend it to variables, function and include calls, constants, and so forth. You cannot prepend it to function or class definitions, or conditional structures such as if and foreach, and so forth.

this mean that if the error is not related to the pure expression ..(like a fatal error) the error i raised ..

Upvotes: 3

Related Questions