文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>[转]类与PHP (III)

[转]类与PHP (III)

时间:2007-02-17  来源:PHP爱好者

Classes and PHP

Great, now what to we do with it? I'm glad you asked. We need to create a few more functions within Style to actually accomplish anything. The first thing I'd like to do is set up my page body so I did this:

<?PHP

function Body() {

PRINT "<BODY BGCOLOR="$this->bgcol" ".
"TEXT="$this->text" ".
"LINK="$this->link" VLINK="$this->vlink" ".
"ALINK="$this->alink"><FONT ".
"FACE="$this->face" SIZE=$this->size>n";

}

?>

This sets up the page body for us. It also illustrates a new variable "$this." When used inside of a class function it lets the interpreter know we are referring to a variable of THIS instance. In other words, it's assigned the value of the name of the instance in the calling line (e.g. $this would be == $Basic when $Basic->Body() is the calling statement.) Also, notice we are doing something here that's much simpler than is possible in regular functions. We're referring to variables that were not passed to the function. Remember, all functions and variables of an instance are available to all functions of that instance. To do this with regular functions you'd have to set up several global arrays.

Try this in your PHP script (assuming you've included the Style class, created the style objects above and sent the <HTML> and <HEAD></HEAD> tags):

<?PHP $Basic->Body(); ?>

Now, we're ready to print something out. We could do it the old fashioned way, but I'm going to do something different... that's right another function:

<?PHP

function TextOut($message=" ") {

PRINT "<FONT FACE="$this->face" ".
"SIZE=$this->size COLOR="$this-> ".
"text">$message</FONT>n";

}

?>
非常全面的一个php技术网站,php爱好者站 http://www.phpfans.net 有相当丰富的文章和源代码.
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载