我需要将“ PHP警告”的内容放入变量中。为此,我得到了以下代码(php类中的set_error_handler()):
padding = 16
with Image(blob=png_image_blob) as foreground:
foreground.transform(resize="{0}x{1}".format(width, height))
with Image(width=width + padding, height=height + padding, background=Color('white')) as out:
left = int((width - padding - foreground.size[0]) / 2) + padding
top = int((height - padding - foreground.size[1]) / 2) + padding
out.composite(foreground, left=left, top=top)
out.save(filename=destination_file_path)
但是出现以下500错误:$data = '';
set_error_handler( function() use ($this, &$data) { $data = $this->my_error_handler(); return $data; } );
//some code that throws Warning
restore_error_handler();
function my_error_handler($errno, $errstr) {
return $errstr;
}
。
如果我将上面的可调用项替换为字符串,则代码可以正常工作而不会出现500错误,但是我无法在其中传递变量并返回带有警告内容的变量。任何想法如何解决?谢谢。