问个php很基础的语法问题

zerozerg2006 2016-12-21 11:58:22
$this->idKey
$this->$idKey
$this->{$idKey}

各是什么意思?有区别吗?
...全文
116 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
傲雪星枫 2016-12-21
  • 打赏
  • 举报
回复
$this->idKey 本类的idKey属性 $this->$idKey $this->{$idKey} 这两个一样 例如$idKey=aaa 则是本类的aaa属性

<?php
class test{

    public $idKey = 0;
    public $aaa = 1;

    public function show(){
        $idKey = 'aaa';
        echo $this->idKey.'<br>';
        echo $this->$idKey.'<br>';
        echo $this->{$idKey}.'<br>';
    }

}

$obj = new test;
$obj->show();

21,893

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧