“DOING_AJAX php version issues” can be translated to “DOING_AJAX PHP版本问题” in Chinese.

huangapple go评论66阅读模式
英文:

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)) {
   ...
}

huangapple
  • 本文由 发表于 2023年4月11日 16:44:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/75983980.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定