PHP类
查看全部词条命名空间:Main
导航: 上一页 | ASP | PHP | JSP | HTML | CSS | XHTML | aJAX | Ruby | JAVA | XML | Python | ColdFusion
类是一个独立的程序单位,是具有相同属性和方法的一组对象的集合。
类的定义
<?php
Class abc
{
//成员函数和变量
}
?>
使用实例
类文件:/class/class.testOne.php
<?php
class testOne{
function __construct(){
echo "begin";
}
function __destruct() {
}
}
?>
类文件:/class/class.testTwo.php
<?php
class testTwo{
protected $name;
function __construct(){
echo "conn";
}
function setName( $name ){
$this->name = $name;
}
function getName(){
return "My name is:".$this->name;
}
function __destruct() {
}
}
?>
文件:/comm.config.php
<?php
function __autoload( $class_name) {
require_once "./class/class.".$class_name.'.php';
}
?>
文件:/index.php
<?php
require_once( "comm.config.php" );
$testOne = new testOne();
?>
输出结果:begin
文件:/index2.php
<?php
require_once( "comm.config.php" );
$testTwo = new testTwo();
$testTwo->setName( "test" );
echo $testTwo->getName();
?>
输出结果:connMy name is:test