问题描述
当我将代码切换到另一个系统时,我收到错误(以下代码所述)
配置:
php服务器:Xampp
请帮助我解决此问题。
代码:
<?php
课堂设置{
公共$主题;
public $ db_pf;
函数__construct(){
$ this-> theme = default;
$ this-> db_pf = task_;
$ this-> paths();
$ this-> abbr();
$ this-> errors();
$ this-> enable_db_config();
}
函数path(){
define(ROOT,$ _ SERVER ['DOCUMENT_ROOT']);
define(BP, / task /);
define(ABSPATH, / task / ta-admin /);
define(ADMPATH, / task / administrator /);
define(INCLUDE_PATH,ABSPATH。 includes /);
define(MODULE_PATH,ABSPATH。 modules /);
define(CONTENT_PATH,ABSPATH。 contents /);
define(THEME_PATH,ABSPATH。 templates /\".$ this-> theme。 /);
define(STYLE_PATH,THEME_PATH。 styles /);
define(IMAGE_PATH,THEME_PATH。 images /);
define(JS_PATH,BP。 assets / js /);
define(JQ_PATH,BP。 assets / jq /);
}
函数enable_db_config(){
include(ROOT.BP。 ta-includes / class-db-config.php);
}
函数abbr(){
define(task_title, Admin-Quit Tasker-);
define(LOGIN_TITLE,管理员登录...);
define(SLOGAN,为您的任务启用解决方案...);
}
function errors(){
define(NOTFOUND,找不到页面);
define(GOBACK,,请按ok返回...);
}
}
$ obj_settings = new settings();
?>
错误:
注意:使用未定义的常量ROOT-在C:xampp\htdocs\task\ta-includes\class-settings.php中假定为'ROOT' 14
注意:使用未定义的常数BP-在第15行$ b中的C:\xampp\htdocs\task\ta-includes\class-settings.php中假定为'BP'
$ b注意:使用未定义的常量ABSPATH-在第16行的C:\xampp\htdocs\task\ta-includes\class-settings.php中假定为'ABSPATH'
注意:使用未定义的常量INCLUDE_PATH-在C:linexampp\htdocs\task\ta-includes\class-settings.php中假定'INCLUDE_PATH'在第17行
注意:使用未定义的常量CONTENT_PATH-在第18行的C:bxampp\htdocs Ctask\ta-includes\class-settings.php中假定为'CONTENT_PATH'
注意:使用未定义常量THEME_PATH的定义-在第19行的C:$ xampp\htdocs $ task\ta-includes\class-settings.php中假定为'THEME_PATH'
注意:使用未定义常量风格_ PATH-在第20行上的C:xampp\htdocs\task\ta-includes\class-settings.php中假设'STYLE_PATH'
注意:使用未定义的常量JS_PATH-假定第21行的C:xampp\htdocs\task\ta-includes\class-settings.php中的'JS_PATH'
注意:使用未定义的常量JQ_PATH-假定为'JQ_PATH'在22行的C:xampp\htdocs\task\ta-includes\class-settings.php中
您的常量必须为字符串。因此,您必须将它们用引号括起来:
define('ROOT',$ _ SERVER ['DOCUMENT_ROOT'] );
^ ^
如有疑问,请始终检查,在这种情况下
添加:
我发现在功能上有点 狡猾。如果您坚持不将它们移动到另一个文件(例如 config
),该文件在开始时就已加载,则至少将它们从类构造中删除。
I receive errors(mentioned below code) when I switched my code to another system,
Configurations:
OS : Windows 7php server : Xampp
Please help me to resolve this problem. thanks in advance.
CODE:
<?php
class settings{
public $theme;
public $db_pf;
function __construct(){
$this->theme="default";
$this->db_pf="task_";
$this->paths();
$this->abbr();
$this->errors();
$this->enable_db_config();
}
function paths(){
define(ROOT,$_SERVER['DOCUMENT_ROOT']);
define(BP,"/task/");
define(ABSPATH,"/task/ta-admin/");
define(ADMPATH,"/task/administrator/");
define(INCLUDE_PATH,ABSPATH."includes/");
define(MODULE_PATH,ABSPATH."modules/");
define(CONTENT_PATH,ABSPATH."contents/");
define(THEME_PATH,ABSPATH."templates/".$this->theme."/");
define(STYLE_PATH,THEME_PATH."styles/");
define(IMAGE_PATH,THEME_PATH."images/");
define(JS_PATH,BP."assets/js/");
define(JQ_PATH,BP."assets/jq/");
}
function enable_db_config(){
include(ROOT.BP."ta-includes/class-db-config.php");
}
function abbr(){
define(task_title,"Admin-Quit Tasker-");
define(LOGIN_TITLE," Administrator Login...");
define(SLOGAN,"Enabling Solutions to your Tasks...");
}
function errors(){
define(NOTFOUND,"Page not found");
define(GOBACK," please press ok to go back...");
}
}
$obj_settings=new settings();
?>
ERRORS:
Notice: Use of undefined constant ROOT - assumed 'ROOT' in C:\xampp\htdocs\task\ta-includes\class-settings.php on line 14
Notice: Use of undefined constant BP - assumed 'BP' in C:\xampp\htdocs\task\ta-includes\class-settings.php on line 15
Notice: Use of undefined constant ABSPATH - assumed 'ABSPATH' in C:\xampp\htdocs\task\ta-includes\class-settings.php on line 16
Notice: Use of undefined constant INCLUDE_PATH - assumed 'INCLUDE_PATH' in C:\xampp\htdocs\task\ta-includes\class-settings.php on line 17
Notice: Use of undefined constant CONTENT_PATH - assumed 'CONTENT_PATH' in C:\xampp\htdocs\task\ta-includes\class-settings.php on line 18
Notice: Use of undefined constant THEME_PATH - assumed 'THEME_PATH' in C:\xampp\htdocs\task\ta-includes\class-settings.php on line 19
Notice: Use of undefined constant STYLE_PATH - assumed 'STYLE_PATH' in C:\xampp\htdocs\task\ta-includes\class-settings.php on line 20
Notice: Use of undefined constant JS_PATH - assumed 'JS_PATH' in C:\xampp\htdocs\task\ta-includes\class-settings.php on line 21
Notice: Use of undefined constant JQ_PATH - assumed 'JQ_PATH' in C:\xampp\htdocs\task\ta-includes\class-settings.php on line 22
Your constants need to be strings. So you have to "wrap" them in quotes like this:
define('ROOT',$_SERVER['DOCUMENT_ROOT']);
^ ^
When in doubt, always check the Manual, in that case define()
Add:
Also defining constants in a function is, what I find, a bit "dodgy". If you insist on not moving them to another (e.g. config
) file which is loaded in the very beginning then at least take them out of the class construct.
这篇关于在PHP中使用未定义的常量erorr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!