QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2264|回复: 5

请教关于PHP中 this 的用法。

[复制链接]
发表于 2005-6-25 17:31:29 | 显示全部楼层 |阅读模式
下面这段代码中的 this 分别代表什么意思?谢谢

<?php
class Foo
{
   function Foo($name)
   {
       global $globalref;
       $globalref[] = &$this;
       $this->setName($name);
       $this->echoName();
   }

   function echoName()
   {
       echo "<br>",$this->name;
   }

   function setName($name)
   {
       $this->name = $name;
   }
}
?>
发表于 2005-6-25 18:52:24 | 显示全部楼层
this 是引用当前 class 里的变量或者函数的 object 。
回复

使用道具 举报

发表于 2005-6-25 19:21:58 | 显示全部楼层
this 是 面向对象语言里面常见的东西 C++ Java都有
回复

使用道具 举报

 楼主| 发表于 2005-6-26 11:32:14 | 显示全部楼层
关于this概念性的东西。我都看过很多了。但好像实际拿源码来看时就迷惑了。
回复

使用道具 举报

发表于 2005-6-26 11:33:48 | 显示全部楼层
看看经典的phpGACL类库使用this的方法,兔兔的phpDMCA参照的它
回复

使用道具 举报

发表于 2005-6-26 13:15:34 | 显示全部楼层
this 就是表示当前的 Class ,基本上只在定义 Class 时才用得到。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-4-19 08:39 , Processed in 0.064143 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表