call_user_func在php中看不到上述变量

时间:2019-07-17 08:07:05

标签: php closures undefined

我有两个缓冲区。代码效果很好:

require("outcomes/forms/beta/backend.php");

ob_start();

    require("outcomes/forms/beta/frontend.php");

$output = str_replace(
                "[@frontend@]",
                ob_get_clean(),
                call_user_func(function () {
                    ob_start();

                        require("layouts/zero/layout.php");

                    return ob_get_clean();
                })
            );

但是,如果我想使代码更整洁,就像这样:

require("outcomes/forms/beta/backend.php");

$output = str_replace(
                "[@frontend@]",
                call_user_func(function () {
                    ob_start();

                        require("outcomes/forms/beta/frontend.php");

                    return ob_get_clean();
                }),
                call_user_func(function () {
                    ob_start();

                        require("layouts/zero/layout.php");

                    return ob_get_clean();
                })
            );

我收到此错误:

未定义变量:[...] / outcomes / forms / beta / frontend.php中的类别

$ categories在上面所需的[/]/outcomes/forms/beta/backend.php中定义。

0 个答案:

没有答案