选择显示字体大小

[转]类与php (ii)


   classes and php

when you create a function within a class with the same name as the class that function will execute whenever you create an object of that class. this is called a 'constructor.' it allows me to have default values for each attribute automatically whenever i create an object:

<?php &#36;basic = new style; ?>

you define an instance of a class by giving it a name (&#36;basic) and assigning it &quot;=new classname;&quot;.

you could also send different values for the variables as arguments when declaring the new style, but if you declare a value you have to declare all of them that occur to the right of the one you declare (class functions work just like regular functions in this respect). meaning if you set &#39;text&#39; to something different than the default given in style, then you have to declare all the variables. there is an easier way. we can create a function that changes a single variable within the class:

<?php

function set(&#36;varname,&#36;value) {

        &#36;this->&#36;varname=&#36;value;

}

?>

so to change the value of particular variable of an instance we can:

<?php &#36;basic->set(&#39;size&#39;,&#39;2&#39;); ?>

you use the &quot;->&quot; operator to refer to a variable or a function of an instance. so the above tells the interpreter &quot;run function &#39;set()&#39; of instance &#39;&#36;basic&#39;.&quot; it knows that &quot;&#36;basic&quot; is an instance of class &quot;styles&quot; because we declared it so. similarly we can refer to variables of an instance in the same manner (e.g. &#36;basic->text).

let&#39;s create a style for table headers that has some slightly different attributes.

<?php

&#36;theader= new style;
&#36;theader->set(&#39;text&#39;,&#39;#0000ff&#39;);
&#36;theader->set(&#39;bgcol&#39;,&#39;#000000&#39;);

?>

there, that&#39;s good enough. now my table header has blue text on a black background. i want my table body to be a slightly lighter gray than my main page, black is good for text, but maybe i&#39;ll make the text smaller:

<?php

&#36;tbody=new style;
&#36;tbody->set(&#39;bgcol&#39;,&#39;#aaaaaa&#39;);
&#36;tbody->set(&#39;size&#39;,2);

?>


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons