比方說,我有兩個文件class.php和page.php文件如何使用PHP類從另一個文件
class.php
<?php
class IUarts {
function __construct() {
$this->data = get_data('mydata');
}
}
?>
這是一個非常rudamentary例子,但讓我們說,我想用:
$vars = new IUarts();
print($vars->data);`
我page.php文件文件
;我該怎麼做呢?如果我做include(LIB.'/class.php');
它大叫我,並給我Fatal error: Cannot redeclare class IUarts in /dir/class.php on line 4
「__autoload()已過時,使用spl_autoload_register(),而不是」 因爲這個結果是在谷歌相當高的,也許有人要編輯並更清楚地指出這一點? – Simon