<?php
class A
{
public static function factorial($n, $accumulator = 1) {
if ($n == 0) {
return $accumulator
}
return function() use($n, $accumulator) {
return self::factorial($n - 1, $accumulator * $n)
}
}
public static function trampoline($params) {
$result = call_user_func_array('self::factorial', $params)
while (is_callable($result)) {
$result = $result()
}
return $result
}
public static function run()
{
var_dump(self::trampoline(array(500)))
}
}
A::run()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)