其他语言

本类阅读TOP10

·基于Solaris 开发环境的整体构思
·使用AutoMake轻松生成Makefile
·BCB数据库图像保存技术
·GNU中的Makefile
·射频芯片nRF401天线设计的分析
·iframe 的自适应高度
·BCB之Socket通信
·软件企业如何实施CMM
·入门系列--OpenGL最简单的入门
·WIN95中日志钩子(JournalRecord Hook)的使用

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
在PHP5中实现自动装载类库

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

Title : 在PHP5中实现自动装载类库
Author : Stangly Wrong


在PHP4中我可以如果需要去装载一个类库文件,比如说 test.inc.php 这个文件, 我们都需要在php文件前使用include或者require(include_once或require_once), 而在PHP5中我们可以采用一种自动的机制,去装载一个类库文件,即使用__autoload()函数;

// test.inc.php

class
Test
{
    var
$name
;

    function
getName
()
    {
         return
$this->name
;
    }
    function
setName($n
)
    {
         
$this->name = $n
;
    }
}
?>

// test.php

// autoload class file
function __autoload($class_name
) {
    include(
$class_name.'.inc.php'
);
}

// instantiate a class
$t = new Test
;

// Call class action
$t->setName('Stangly Wrong'
);
echo
$t->getName
();

?>



相关文章

相关软件