@@ -149,9 +149,8 @@ protected function getDefaultModuleValue(bool $isDark):int{
149149 */
150150 public function dump (string $ file = null ){
151151
152- /** @phan-suppress-next-line PhanTypeMismatchArgumentInternal */
153- set_error_handler (function (int $ severity , string $ msg , string $ file , int $ line ):void {
154- throw new ErrorException ($ msg , 0 , $ severity , $ file , $ line );
152+ set_error_handler (function (int $ errno , string $ errstr ):bool {
153+ throw new ErrorException ($ errstr , $ errno );
155154 });
156155
157156 $ this ->setBgColor ();
@@ -272,6 +271,8 @@ protected function setPixel(int $x, int $y):void{
272271 * @throws \chillerlan\QRCode\Output\QRCodeOutputException
273272 */
274273 protected function dumpImage ():string {
274+ $ exception = null ;
275+
275276 ob_start ();
276277
277278 try {
@@ -289,19 +290,23 @@ protected function dumpImage():string{
289290 imagepng ($ this ->image , null , max (-1 , min (9 , $ this ->options ->pngCompression )));
290291 }
291292
293+ $ imageData = ob_get_contents ();
294+ imagedestroy ($ this ->image );
292295 }
293296 // not going to cover edge cases
294297 // @codeCoverageIgnoreStart
295298 catch (Throwable $ e ){
296- throw new QRCodeOutputException ( $ e -> getMessage ()) ;
299+ $ exception = $ e ;
297300 }
298301 // @codeCoverageIgnoreEnd
299302
300- $ imageData = ob_get_contents ();
301- imagedestroy ($ this ->image );
302-
303303 ob_end_clean ();
304304
305+ // throw here in case an exception happened within the output buffer
306+ if ($ exception instanceof Throwable){
307+ throw new QRCodeOutputException ($ exception ->getMessage ());
308+ }
309+
305310 return $ imageData ;
306311 }
307312
0 commit comments