swoole / phpy

Connecting the Python and PHP ecosystems together
Apache License 2.0
543 stars 44 forks source link

任意调用python内置函数及其他 #14

Closed he426100 closed 11 months ago

he426100 commented 11 months ago

class MyPy extends PyCore { protected static $py;

public static function instance()
{
    if (!self::$py) {
        self::$py = self::import('builtins');
    }
    return self::$py;
}

public static function dump($e) { var_dump(self::scalar($e)); }

public static function __callStatic($name, $arguments)
{
    return self::instance()->$name(...$arguments);
}

}

MyPy::dump(MyPy::range(1, 10, 2)) array(5) { [0]=> int(1) [1]=> int(3) [2]=> int(5) [3]=> int(7) [4]=> int(9) }