警告:require_once():无法打开流:没有这样的文件或目录

Warning: require_once(): failed to open stream: No such file or directory in

我包括 PHP Class 这样的 require_once(realpath($_SERVER["DOCUMENT_ROOT"]).'\xampp\htdocs\aclass\classfile.php');

但是当我执行代码时出现错误

Warning: require_once(C:\xampp\htdocs\xampp\htdocs\aclass\classfile.php): failed to open stream: No such file or directory in C:\xampp\htdocs\aclass\index.php on line 2
Fatal error: require_once(): Failed opening required 'C:\xampp\htdocs\xampp\htdocs\aclass\classfile.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\aclass\index.php on line 2

fileclass.php

    <?php  
class Test{
    public function hello(){
        echo "hello every one";
    }
}

testclass.php

<?php

require_once (realpath($_SERVER["DOCUMENT_ROOT"]).'\xampp\htdocs\aclass\classfile.php');
$var=new Test();
$var->hello();

提前致谢!!

DOCUMENT_ROOT已经在\xampp\htdocs中了,所以你可以跳过那部分:

require_once(realpath($_SERVER["DOCUMENT_ROOT"]).'\aclass\classfile.php');