@@ -53,9 +53,30 @@ private function writePhpFunction(): string
5353 $ moduleName = $ this ->method ->getModuleName ();
5454
5555 $ phpFunction .= "function {$ this ->method ->getFunctionName ()}( {$ this ->displayParamsWithType ($ this ->method ->getParams ())}) {$ returnType }
56- {
57- error_clear_last();
58- " ;
56+ { " ;
57+
58+ $ includeErrorHandler = true ;
59+ // Certain methods from curl don't need the custom error handler
60+ if ($ moduleName !== 'Curl ' ) {
61+ $ params = $ this ->method ->getParams ();
62+ if (\count ($ params ) > 0 && in_array ($ params [0 ]->getParameter (), ['handle ' , 'multi_handle ' , 'share_handle ' ])) {
63+ $ includeErrorHandler = false ;
64+ }
65+ }
66+
67+ if ($ includeErrorHandler ) {
68+ $ phpFunction .= "
69+ \$error = [];
70+ set_error_handler( function(int \$errno, string \$errstr, string \$errfile, int \$errline) use (& \$error) {
71+ \$error = [
72+ 'type' => \$errno,
73+ 'message' => \$errstr,
74+ 'file' => \$errfile,
75+ 'line' => \$errline,
76+ ];
77+ return false;
78+ }); \n" ;
79+ }
5980
6081 if (!$ this ->method ->isOverloaded ()) {
6182 $ phpFunction .= ' $result = ' .$ this ->printFunctionCall ($ this ->method );
@@ -88,6 +109,7 @@ private function writePhpFunction(): string
88109 $ phpFunction .= ' $result = ' .$ this ->printFunctionCall ($ method )."\n" ;
89110 $ phpFunction .= ' } ' ;
90111 }
112+ $ phpFunction .= "\n restore_error_handler(); \n" ;
91113
92114 $ phpFunction .= $ this ->generateExceptionCode ($ moduleName , $ this ->method ).$ returnStatement . '}
93115 ' ;
@@ -126,7 +148,7 @@ private function generateExceptionCode(string $moduleName, Method $method) : str
126148 $ exceptionName = FileCreator::toExceptionName ($ moduleName );
127149 return "
128150 if ( \$result === $ errorValue) {
129- throw {$ exceptionName }::createFromPhpError();
151+ throw {$ exceptionName }::createFromPhpError( \$ error );
130152 }
131153 " ;
132154 }
0 commit comments