Search code examples
phpfatal-errorrequire-once

require_once fatal error (one more time)


I have created super simple script as same as before when everything worked properly. But somehow it stopped and now everytime I try to require a file it show me an error:

Fatal error: require_once(): Failed opening required 'E:\tools\EasyPHP\www/registry/registry.class.php' (include_path='.;C:\php\pear') in E:\tools\EasyPHP\www\index.php on line 18

My index file:

define("APP_PATH", dirname(__FILE__)."/");
require_once(APP_PATH.'registry/registry.class.php');

That is everything but i still can't load that page.

How should i set it up? I'm using windows for local builds only.


Solution

  • define( "APP_PATH", dirname( __FILE__ ) . DIRECTORY_SEPARATOR );
    require_once( APP_PATH . 'registry' . DIRECTORY_SEPARATOR . 'registry.class.php' );
    

    The constant DIRECTORY_SEPARATOR evaluates to backslash on Windows systems and forward-slash on *nix systems. This way your code will work without modification on both Windows and Linux environments.

    (See the PHP manual on this constant and its friend PATH_SEPARATOR.)

    If you're still having trouble, it's possible the file does not exist at that path, or that PHP does not have read permissions to the file.