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条)

报告相同问题?

悬赏问题

  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏