在运行时候动态添加函数

    1. use Illuminate\Support\Collection;
    2. Collection::macro('someMethod', function ($arg1 = 1, $arg2 = 1) {
    3. return $this->count() + $arg1 + $arg2;
    4. });
    5. $coll = new Collection([1, 2, 3]);
    6. echo $coll->someMethod(1, 2);
    7. // 6 = 3 + (1 + 2)
    8. echo $coll->someMethod();
    9. // 5 = 3 + (1 + 1)