0
我在想,如果我能在PHP中像JavaScript一样,应用函数调用来返回一个对象。在JavaScript中,我可以这样做:模拟JavaScript扩展函数
var y = 1;
var x = y.toString().concat(' + 1');
console.log(x);
而且我认为如果PHP中可以做到几乎相同。我在考虑递归到这一点,我不知道名称来完成搜索。我试图,在这一刻:
<?php
class Main {
public function __construct() {
$this->Main = new Main;
}
public function merge(/* this */ $xs, $ys) {
return array_merge($xs, $ys);
}
public function add(/* this */ $xs, $ys) {
return array_push($xs, $ys);
}
}
$aux = new Main;
$x = $aux -> merge([1, 2, 3], [4, 5, 6])
-> add(7)
-> add(8)
-> add(9);
// $x => [1, 2, 3, 4, 5, 6, 7, 8, 9]
?>
这是溢出的一切。我收到一条溢出消息:
Maximum function nesting level of '100' reached
我能做到这一点吗?几乎与C#扩展方法相同。