• PHP Help
  • anyone can help me? how to solve this error? :(

Use of undefined constant LIB_PATH - assumed 'LIB_PATH' (this will throw an Error in a future version of PHP)

Fatal error: require_once(): Failed opening required 'LIB_PATHDSconfig.php' (include_path='C:\xampp\php\PEAR')
this is my code.

defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);

defined('SITE_ROOT') ? null : define ('SITE_ROOT', $_SERVER['DOCUMENT_ROOT'].DS.'sscbc');

defined('LIB_PATH') ? null : define ('LIB_PATH',SITE_ROOT.DS.'include');

    So you're not running the code you posted before running whatever code it is that's throwing the error so that those constants aren't being defined.

    (Incidentally, it would be more appropriate to use "A or B" instead of "A ? null : B".)

    Weedpacket
    sorry sir I'm still a beginner. can you give me an idea to fix it or suggestions.

      Basically, either whatever line of code is actually outputting those error messages (which is not in the code you pasted here) is being run before the code you pasted is executed, or the code you pasted is never actually being run at all. Thus the constants LIB_PATH and DS are not defined when that require_once call is made.

        When you see all uppercase stuff like LIB_PATH, that usually refers to a constant someone has defined like this:

        define('LIB_PATH', '/var/www/public/library/');

        If you try to refer to some constant which hasn't been defined yet -- or just happened to accidentally leave the $ off a variable you were typing -- then you get the undefined constant error. This commonly happens:

        echo FOO; // this causes error

        The error in this case is:

        PHP Warning:  Use of undefined constant FOO - assumed 'FOO' (this will throw an Error in a future version of PHP) in /tmp/foo.php on line 3

        This often happens if you forget to include or require some file that would initialize your framework or coding environment.

          Write a Reply...