0

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!

johnvantes
  • 29
  • 7
  • 3
    The suppressor-operator only prevents the error from being logged. If it's a fatal error, the script will still stop executing. You can wrap it with `function_exists()`, and only use it if it's defined. – Qirel Jul 11 '16 at 19:21
  • 2
    `@` doesn't prevent errors, it will just suppress them so they aren't shown. – aynber Jul 11 '16 at 19:21
  • 1
    http://stackoverflow.com/questions/1032161/what-is-the-use-of-the-symbol-in-php – Ovidiu Bute Jul 11 '16 at 19:21
  • 4
    `@` doesn't prevent fatal errors, just like wrapping your head in a towel doesn't prevent you from getting hit in the head with a baseball bat. All it does is prevent you from seeing things. – Marc B Jul 11 '16 at 19:25
  • are you getting the error because of wrong server url? – unixmiah Jul 11 '16 at 19:32
  • @RyanVincent So I bought the script from codecanyon.net, a certain function isn't working and I am not getting any error whatsoever, so it turns out that line is getting the script terminated without giving error, I thought `@` will suppress error and let the script going, how silly of me. – johnvantes Jul 11 '16 at 19:35
  • Thanks Qirel and Marc B, your answers clear things up for me. – johnvantes Jul 11 '16 at 19:37
  • when you say certain function? are you talking about a ufo? you should go through the entire script and make sure it's in a working order; maybe you didn't follow right documentation and system requirements. – unixmiah Jul 11 '16 at 19:43
  • 1
    @unixmiah unfortunately the documentation is minimal and isn't mentioning anything about requiring ftp module. Also the script author suppressed the error made me confused on what was wrong, I finally found out the error using `register_shutdown_function ` from this answer http://stackoverflow.com/a/2146171/4561463. – johnvantes Jul 11 '16 at 19:55

2 Answers2

3

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 ..

ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
1

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

Toby Allen
  • 10,997
  • 11
  • 73
  • 124