使用register

编程入门 行业动态 更新时间:2024-10-25 12:28:47
使用register_shutdown_function()时,为什么我的'关闭回调'无效?(Why is my 'shutdown callback ' invalid when using register_shutdown_function()?)

警告:register_shutdown_function():无效的关闭回调

trait ErrorTrait { public function shutDownFunction() { $error = error_get_last(); // fatal error, E_ERROR === 1 if ($error['type'] === E_ERROR) { //do your stuff $messageStore="Using $this when not in object context"; if (strstr ( $error['message'],$messageStore)) { echo "found it"; } } } public function shutdown_function() { register_shutdown_function('shutDownFunction'); }

}

我在我的主类中使用这个特性并从中调用函数

use ErrorTrait; public function test() { self::shutDownFunction(); self::shutdown_function(); }

然后在这一点上,我在一个名为“run”的函数中调用test中的函数

我所做的只是简单地调用函数。

public function run() { self::test (); // Rest of code}

有关为什么会导致问题的任何想法?

Warning: register_shutdown_function(): Invalid shutdown callback

trait ErrorTrait { public function shutDownFunction() { $error = error_get_last(); // fatal error, E_ERROR === 1 if ($error['type'] === E_ERROR) { //do your stuff $messageStore="Using $this when not in object context"; if (strstr ( $error['message'],$messageStore)) { echo "found it"; } } } public function shutdown_function() { register_shutdown_function('shutDownFunction'); }

}

I use this trait in my main class and call the functions from it

use ErrorTrait; public function test() { self::shutDownFunction(); self::shutdown_function(); }

And then at this point I call the function in test in a function called "run"

All I do is a simply call the function.

public function run() { self::test (); // Rest of code}

Any ideas as to why this is causing problems?

最满意答案

您正在将字符串而不是可调用字符传递给register_shutdown_function 。 电话应该是这样的

register_shutdown_function([$this, 'shutDownFunction']);

You are passing a string instead of a callable into register_shutdown_function. The call should look like

register_shutdown_function([$this, 'shutDownFunction']);

                    
                     
          

更多推荐

本文发布于:2023-08-04 16:56:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1417719.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:register

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!