我的代码没有读取 PHP 中定义的常量
大家好 我有一个使用 PHP 的项目,该项目分为管理部分和客户端部分。
客户端 ecd 工作得很好。但我无法访问我的管理部分,并且显示错误消息
致命错误:在第 30 行的 E:\wamp\www\dfms\admin\index.php 中找不到类“ClsBase”
致命错误:在第 30 行更新
是 $base_obj = new ClsBase();< /code>
UPDATE1
第 14 行:include_once(ADMIN_CLASS_DIR ."ClsAdminUser.php");
但我已经在我的 adminconfig.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.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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有看到代码,很难判断。有两个可能的问题。
ADMIN_CLASS_DIR
未设置,因此 PHP 将发出通知
并默认为ADMIN_CLASS_DIR
。您的代码如下所示:要修复它,只需定义目录:
您尝试在字符串文字内使用它:
PHP 中的常量不是这样工作的。它们仅在字符串之外解析。所以你可以这样做:
或者,如果您需要将常量定义为字符串,您可以这样做:
要判断常量是否已定义,请使用
定义
函数。如果定义了常量,它将返回true
。如果您需要更好的帮助,请发布一些代码!
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:To fix it, just define the directory:
You're trying to use it inside of a string literal:
Constants in PHP don't work like that. They are only resolved outside of a string. So you could do either:
Or you could do this if you needed to define the constant as a string:
To tell if the constant is defined, use the
defined
function. It'll returntrue
if the constant is defined.If you want better help than that, post some code!
看起来您希望设置一个常量
ADMIN_CLASS_DIR
,但事实并非如此。 PHP 将发出一个通知,然后假设该常量是一个字符串文字。你在哪里定义这个常数?您需要将该代码包含在脚本中。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.看起来您在到达使用常量的代码块之前没有定义该常量。
不过,您应该会收到一条通知:
这表明 PHP 将假定它是一个字符串。并这样对待它。
免责声明/题外话:
PHP 确实有一些奇怪的问题
Looks like you didn't define the constant before you got to the codeblock which uses it.
You should get a notice though:
This states that PHP will assume it is a string. And treats it this way.
Disclaimer / Offtopic:
PHP really has some weird issues