在php中使用未定义的常量错误 [英] Use of undefined constant error in php

查看:48
本文介绍了在php中使用未定义的常量错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码

<?php
 $email_domain = "abc@gmail.com";
 $email_user = "Roshan";
 $email_pass = "admin";
 $email_quota = "200";
 $call = array(domain=>$email_domain, email=>$email_user, password=>$email_pass, quota=>$email_quota);

 echo json_encode($call);
?>

产生以下错误:

Notice: Use of undefined constant domain - assumed 'domain' in C:\xampp\htdocs\test2.php on line 7

Notice: Use of undefined constant email - assumed 'email' in C:\xampp\htdocs\test2.php on line 7

Notice: Use of undefined constant password - assumed 'password' in C:\xampp\htdocs\test2.php on line 7

Notice: Use of undefined constant quota - assumed 'quota' in C:\xampp\htdocs\test2.php on line 7
{"domain":"abc@gmail.com","email":"Roshan","password":"admin","quota":"200"}

我想知道这种情况的发生,以及在这种情况下可以采取哪些措施来防止出现此错误.

I want to know the occurrence of this and in this case what can be done to prevent this error.

推荐答案

array(name => value) is not a valid syntax, php 现在没有什么 name是.您需要在数组键周围加上引号.

array(name => value) is not a valid syntax, php doesn't now what name is. You need quotation marks around your array keys.

使用 array("domain" => $email_domain, ...

这篇关于在php中使用未定义的常量错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆