欢迎光临
我们一直在努力

[转]类与PHP (III)-PHP教程,PHP应用

建站超值云服务器,限时71元/月

classes and php

great, now what to we do with it? im glad you asked. we need to create a few more functions within style to actually accomplish anything. the first thing id 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, its 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 thats much simpler than is possible in regular functions. were 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 youd have to set up several global arrays.

try this in your php script (assuming youve included the style class, created the style objects above and sent the <html> and <head></head> tags):

<?php $basic->body(); ?>

now, were ready to print something out. we could do it the old fashioned way, but im going to do something different… thats right another function:

<?php

function textout($message="&nbsp") {

        print "<font face=\"$this->face\" ".
                "size=$this->size color=\"$this-> ".
                "text\">$message</font>\n";

}

?>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » [转]类与PHP (III)-PHP教程,PHP应用
分享到: 更多 (0)