My code doesnt read the defined constants in PHP
Hi All I have a project working in PHP which is divided in an admin section and client section.
Client ecd is working perfectly fine. But I Cannot access my admin section and it displays the error saying
Fatal error: Class 'ClsBase' not found in E:\wamp\www\dfms\admin\index.开发者_Go百科php on line 30
UPDATE
line 28 is $base_obj = new ClsBase();
UPDATE1
LINE 14:include_once(ADMIN_CLASS_DIR ."ClsAdminUser.php");
But I have defined all the constants in my adminconfig.php
And I am using the Constant to give the path to this file and also this file present in the required folder
Could you please help me What could be the problem?
Without seeing code, it's hard to tell. There are two possible problems.
ADMIN_CLASS_DIR
is not set, so PHP will issue anotice
and default toADMIN_CLASS_DIR
. Your code would look like:include_once(ADMIN_CLASS_DIR . 'ClsAdminUser.php');
To fix it, just define the directory:
if (!defined('ADMIN_CLASS_DIR')) { define('ADMIN_CLASS_DIR', 'path/to/dir'); }
You're trying to use it inside of a string literal:
include_once('ADMIN_CLASS_DIR/ClsAdminUser.php');
Constants in PHP don't work like that. They are only resolved outside of a string. So you could do either:
include_once(ADMIN_CLASS_DIR . '/ClsAdminUser.php');
Or you could do this if you needed to define the constant as a string:
include_once(constant('ADMIN_CLASS_USER') . '/ClsAdminUser.php');
To tell if the constant is defined, use the defined
function. It'll return true
if the constant is defined.
If you want better help than that, post some code!
Looks like you expect a constant ADMIN_CLASS_DIR
to be set, when it's not. PHP will issue a notice and then assume that the constant is a string literal. Where do you define this constant? You need to include that code in your script.
Looks like you didn't define the constant before you got to the codeblock which uses it.
You should get a notice though:
Notice: Use of undefined constant ADMIN_CLASS_DIR - assumed 'ADMIN_CLASS_DIR'
This states that PHP will assume it is a string. And treats it this way.
Disclaimer / Offtopic:
PHP really has some weird issues
精彩评论