1
votes

I'm including PHP Class like that require_once(realpath($_SERVER["DOCUMENT_ROOT"]).'\xampp\htdocs\aclass\classfile.php');

but when i executed the code thow a error

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();

thank you in advance!!

1
You're most likely typing the wrong path. Just in the code you've shared you mention classfile.php and fileclass.php :-?Álvaro González

1 Answers

3
votes

The DOCUMENT_ROOT is already in \xampp\htdocs, so you can skip that part:

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