我使用PHP 5.2.3,但使用PHP 5.3的教程老師我正在編寫相同的代碼,但我只能看到錯誤。我的代碼和教程代碼有什麼區別?
路徑:
Main
---index.php
---com
---User.php
<?php
define('APPLICATION_PATH', realpath('../'));
$paths = array(
APPLICATION_PATH,
APPLICATION_PATH . '/com',
get_include_path()
);
print_r($paths);
set_include_path(implode(PATH_SEPARATOR, $paths));
require_once('User.php');
$user = new User();
$user->getName();
錯誤:
Warning: require_once(User.php) [function.require-once]: failed to open stream: No such file or directory in C:\AppServ\www\advanced\index.php on line 11
Fatal error: require_once() [function.require]: Failed opening required 'User.php' (include_path='C:\AppServ\www;C:\AppServ\www/com;.;C:\php5\pear') in C:\AppServ\www\advanced\index.php on line 11
爲什麼我的代碼沒有運行?
也許你需要(user.php的):
<?php
Class User
{
public function getName()
{
return "Ricardo Quaresma";
}
}
?>
哪裏是文件user.php的? – christophmccann 2012-03-02 22:12:27
您的第二個'$ paths'條目具有正斜槓。它應該是反斜槓嗎? – SenorAmor 2012-03-02 22:14:47
它不會改變任何東西.. @SenorAmor – Joseph 2012-03-02 22:20:39