• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

[转]类与PHP (III)

发布: 2007-7-01 15:06 | 作者: admin | 来源: | 查看: 14次 | 进入软件测试论坛讨论

领测软件测试网 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";

}

?>

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网