duanfan8360 2017-07-09 20:52
浏览 51
已采纳

它有什么作用 ? (PHP特质)

I just found this code and I have got no idea how to google it. :-)

What does the last trait do ? I cannot understand it's syntax. If those lines between the curly braces would be parameters for a new instance, shouldn't it be between parentheses?

<?php

namespace Laravel\Dusk;

use Closure;
use BadMethodCallException;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;
use Facebook\WebDriver\WebDriverDimension;

class Browser
{
    use Concerns\InteractsWithAuthentication,
        Concerns\InteractsWithCookies,
        Concerns\InteractsWithElements,
        Concerns\InteractsWithJavascript,
        Concerns\InteractsWithMouse,
        Concerns\MakesAssertions,
        Concerns\WaitsForElements,
        Macroable {
            __call as macroCall;
        }

    // ...

}

The code is from Laravel\Dusk. Here is the original GitHub repository and the Class itself

  • 写回答

1条回答 默认 最新

  • donglulong0877 2017-07-09 20:58
    关注

    This:

    namespace Laravel\Dusk;
    
    use Illuminate\Support\Traits\Macroable;
    
    class Browser
    {
        use Macroable {
           __call as macroCall;
        }
    
        public function __call($method, $parameters)
        {
            // this is defined in THIS class
        }
    }
    

    Just aliases the __call method from Macroable trait and makes it available as

    $this->macroCall($method, $parameters)
    

    This is needed to avoid the conflict of the __call method which is defined in both this class and the imported trait

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀