PHP: Nasıl tespit edebilir "@"

2 Cevap php

Ben E_ALL PHP hataları bağlı bir özel hata işleyicisi var.

Harici lib çağrı $row = @mysql_fetch_assoc($this->result); Benim işleyicisi tarafından yakalandı PHP Uyarılar tetikler. Neden? '@' PHP bu görmezden yapmak gerekmez mi?

Benim soru: '@' kullanılmış olduğunu (benim hata işleyici) algılayabilir herhangi bir yolu var mı?

2 Cevap

PHP kılavuzda hızlı bir bakış ortaya çıkardı:

It is important to remember that the standard PHP error handler is completely bypassed. error_reporting() settings will have no effect and your error handler will be called regardless - however you are still able to read the current value of error_reporting and act appropriately. Of particular note is that this value will be 0 if the statement that caused the error was prepended by the @ error-control operator.

http://de.php.net/manual/en/function.set-error-handler.php

@ Operatörü kullanılarak btw oldukça bazı insanlar tarafından kötü tarzı olarak kabul edilir.

PHP Manual üzerine set_error_handler gösterileri başvurma

It is important to remember that the standard PHP error handler is completely bypassed. error_reporting() settings will have no effect and your error handler will be called regardless - however you are still able to read the current value of error_reporting and act appropriately. Of particular note is that this value will be 0 if the statement that caused the error was prepended by the @ error-control operator.

Peki bu yapabilirdi:

function my_error_handler($errno, $errstr) {
  if (error_reporting() == 0) { // called with @
    return;
  }
  //....
}