I’ve embedded Haxe classes into an existing php website by compiling it to PHP using haxephp.
Since then all Notices & Warnings happen to be fatal, so many things are broken.
For example: count() on non irritable
, or $_GET["nonexistent"]
are now fatal.
The stack-trace is a Haxe style stack trace, so I do understand this has something to do with haxe overriding the exception handling.
I tried to search the PHP site about overriding exception but didn’t found anything helpful.
How can I lower the strictness and make php continue on those kinds of errors?
Asked here but no response
Here’s how Haxe overrides error handling on php:
if (!Global.defined('HAXE_CUSTOM_ERROR_HANDLER') || !Const.HAXE_CUSTOM_ERROR_HANDLER) {
var previousLevel = Global.error_reporting(Const.E_ALL);
var previousHandler = Global.set_error_handler(function(errno:Int, errstr:String, errfile:String, errline:Int) {
if (Global.error_reporting() & errno == 0) {
return false;
}
/*
* Division by zero should not throw
* @see https://github.com/HaxeFoundation/haxe/issues/7034#issuecomment-394264544
*/
if (errno == Const.E_WARNING && errstr == 'Division by zero') {
return true;
}
throw new ErrorException(errstr, 0, errno, errfile, errline);
});
// Already had user-defined handler. Return it.
if (previousHandler != null) {
Global.error_reporting(previousLevel);
Global.set_error_handler(previousHandler);
}
}
As you can see, to disable that you can either define HAXE_CUSTOM_ERROR_HANDLER
constant or setup your own error handler in your php scripts prior to inclusion of Haxe-generated php.
But keep in mind that without such warnings-to-exceptions conversion Haxe code won’t throw on null pointer access or on attempt to read a non-existent file etc. And some Haxe libraries may rely on those exceptions being thrown.
Hi Thanks
I hope to sanitize my website of all warnings, but in the meantime i couldn’t afford to break certain pages.