Domanda

I have noticed that using php's error_reporting function at runtime seems to cause it to report notices that have occurred previously.

Is this by design, or is there a way to prevent it?

$er = error_reporting(E_ERROR);
$m = new MyClass();
$m->myFunction();
//error_reporting($er);  

In the above code, myFunction() calls 3rd-party code that raises warnings and/or "strict" notices. If the last line is commented out as it is above, those warnings and notices are not returned. However, if I uncomment that line so that error reporting can return to normal, the strict notices, but not the warnings, are reported at that point.

Update I think this is not a problem with error_reporting as I had originally thought, but instead an issue with Pear, the 3rd-party code I'm using.

See my post at php pear mail extension raises strict notices

È stato utile?

Soluzione

I have noticed that using php's error_reporting function at runtime seems to cause it to report notices that have occurred previously.

What you said is just regular behaviour at must related to parts of your code which you havn't posted. Check my example. It will call a non static method statically what will cause a E_STRICT message:

Class A { 
    public function notStatic() {}
}

$a = new A();

error_reporting(~E_ALL);
$a::notStatic();   // ... silence

error_reporting(E_ALL);
$a::notStatic();   // Strict standards: Non-static method A::notStatic() should not be called statically in 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top