没有这个,如何在一个类中声明一个函数?

<?php

class modul {

    var $i=1;
    var $j=1;

    public function init(){
        $test1 = function($vRecord){
            return 'zwrot';
        };
        echo "<pre>";
        print_r($test1);
        echo "</pre>";
    }

}

$modul = new modul();
$modul->init();


我打印时的结果:

Closure Object
(
    [this] => modul Object
        (
            [i] => 1
            [j] => 1
        )

    [parameter] => Array
        (
            [$vRecord] =>
        )

)


如何不通过键传递功能:“ this”?我想要一个在print_r中的纯函数,结果如下:

码:

<?php
$test2 = function($vRecord){
    return 'zwrot';
};
echo "<pre>";
    print_r($test2);
echo "</pre>";


当我打印结果:

Closure Object
(
    [parameter] => Array
        (
            [$vRecord] =>
        )

)

最佳答案

您可以定义Static anonymous function

    $test1 = static function($vRecord){
        return 'zwrot';
    };

10-06 14:45