@@ -53,9 +53,30 @@ private function writePhpFunction(): string
53
53
$ moduleName = $ this ->method ->getModuleName ();
54
54
55
55
$ 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
+ }
59
80
60
81
if (!$ this ->method ->isOverloaded ()) {
61
82
$ phpFunction .= ' $result = ' .$ this ->printFunctionCall ($ this ->method );
@@ -88,6 +109,7 @@ private function writePhpFunction(): string
88
109
$ phpFunction .= ' $result = ' .$ this ->printFunctionCall ($ method )."\n" ;
89
110
$ phpFunction .= ' } ' ;
90
111
}
112
+ $ phpFunction .= "\n restore_error_handler(); \n" ;
91
113
92
114
$ phpFunction .= $ this ->generateExceptionCode ($ moduleName , $ this ->method ).$ returnStatement . '}
93
115
' ;
@@ -126,7 +148,7 @@ private function generateExceptionCode(string $moduleName, Method $method) : str
126
148
$ exceptionName = FileCreator::toExceptionName ($ moduleName );
127
149
return "
128
150
if ( \$result === $ errorValue) {
129
- throw {$ exceptionName }::createFromPhpError();
151
+ throw {$ exceptionName }::createFromPhpError( \$ error );
130
152
}
131
153
" ;
132
154
}
0 commit comments