?
定义类BBB,并保存为BBB.php,内容如下:
class="php" name="code"><?php class BBB{ private $name; function __construct($name){ $this->name = $name; } function hello() { echo $this->name; } } ?>
?
?
编写测试用php文件,保存为AAA.php,内容如下:
<?php require_once 'BBB.php'; if(class_exists('BBB')){ $bbb = new BBB('张三'); $bbb->hello(); echo "<br>"; $class = BBB; $bbb = new $class('李四'); $bbb->hello(); echo "<br>"; $class = 'BBB'; $bbb = new $class('王五'); $bbb->hello(); } ?>
?
通过浏览器访问AAA.php,输出结果如下:
张三<br>李四<br>王五
?
?http://huangqiqing123.iteye.com/blog/1932103
?