英文:
DOING_AJAX php version issues
问题
我使用PHP 7.4.12版本时收到此通知 :使用未定义的常量DOING_AJAX - 假定为'DOING_AJAX'(这将在未来的PHP版本中引发错误)
而在PHP 8中,我收到了这个错误 致命错误:未捕获的错误:未定义的常量"DOING_AJAX"
导致这个问题的是这个函数中的第二行(if (!is_admin() || (defined(DOING_AJAX) && DOING_AJAX)) { )
能否有人指导我在这个问题上的正确方向?
英文:
I am getting this notice with PHP 7.4.12 version : Use of undefined constant DOING_AJAX - assumed 'DOING_AJAX' (this will throw an Error in a future version of PHP) in
And with PHP 8 I am getting this error Fatal error: Uncaught Error: Undefined constant "DOING_AJAX" in
It is the second line in this function that is causing it. ( if (!is_admin() || (defined(DOING_AJAX) && DOING_AJAX)) { )
private function init() {
if (!is_admin() || (defined(DOING_AJAX) && DOING_AJAX)) {
$this->frontend = new Woo_Custom_CSV_Builder_Frontend();
}
if (isset($_GET['file'])) {
//$this->handle_download();
}
}
Could someone point to right direction with this issue?
答案1
得分: 3
如文档所述,defined
函数的用法是:defined(string $constant_name): bool
。
您必须将一个字符串作为defined
的参数。在您的情况下,给出了一个常量。在早期的PHP版本中,尽管这是一个明显的错误,但也是可以的。
只需使用以下方式:
if (!is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) {
...
}
英文:
As the documentation states out the usage of the defined
function: defined(string $constant_name): bool
.
You have to give a string as the parameter of defined. In your case a constant is given. In earlier PHP versions this was okay although this is an obvious error.
Just use the following:
if (!is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) {
...
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论