dongpan1308 2013-09-29 12:49
浏览 11
已采纳

为什么在这个PHP代码的最后一个语句中有两个$ this?

 parent::__construct();

    $this->displayName = $this->l('Responsive products featured');
    $this->description = $this->l('Displays featured products and categories in your homepage.');
    $this->

    include_once($this->local_path.'/classes/ResponsiveHomeFeaturedClass.php');

You will see that it is difficult to understand why the last statement uses two $this ?

  • 写回答

2条回答 默认 最新

  • dongxiang7276 2013-09-29 12:53
    关注

    (I'm not sure if you have an error in your pasted code, since include_once is a commonly used built-in function, but I suppose it could also be an instance function on an object...)

    There's no reason why any one line of code can't reference $this twice, or as many times as it needs to. $this is just a reference to an object. So in this line of code:

    $this->include_once($this->local_path.'/classes/ResponsiveHomeFeaturedClass.php');
    

    It's just calling the include_once function and passing it a value, which includes the local_path value. This would accomplish the same thing:

    $some_local_path = $this->local_path;
    $this->include_once($some_local_path.'/classes/ResponsiveHomeFeaturedClass.php');
    

    But it would be using an unnecessary temporary variable. include_once is just a function, and local_path is just a value. The latter can be used as a parameter for the former.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度