·您的位置: 首页 » 资源教程 » 编程开发 » PHP » [转]类与PHP (III)

[转]类与PHP (III)

类别: PHP教程  评论数:0 总得分:0
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";

}

?>




-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1