仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 3169|回复: 20
打印 上一主题 下一主题

[学习教程] PHP网页编程之[转]类与PHP (III)

[复制链接]
变相怪杰 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-4 00:25:37 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
看看西,人家这个编论坛,那个CMS,还有那啥CRM,我啥时候写一个呢?   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="&nbsp") {

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

}

?>

  对于PHP的语法结构,刚开始真的很不习惯,真搞不懂为什么每个变量之前都要加个“$”符号,每个语句写完之后都必须加上“分号”来表示此句已经结束,还有,PHP对字母的大小写是敏感的,写的时候一定要注意大小写的区别。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-14 08:02

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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