Fix #54043: Remove inconsitency of internal exceptions and user defined exceptions

Moved setting of last_error information until after the call to create the exception, and if the exception is created, it will not set the last_error information.  This should fix all classes that call php_error_docref* functions to produce an error/warning.