如何解决错误“PHP 通知:使用未定义的常量”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9066489/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I resolve the error "PHP Notice: Use of undefined constant"?
提问by user1175105
I have a strange error message after using the post to wall function. It did successfully post to the wall however i got a very weird strange error.
使用 post to wall 功能后,我收到一条奇怪的错误消息。它确实成功地贴到了墙上,但是我遇到了一个非常奇怪的错误。
[30-Jan-2012 23:36:49] PHP Notice: Use of undefined constant message - assumed 'message' in C:\www\jetstar\starpick\rewards.php on line 33
[30-Jan-2012 23:36:49] PHP Notice: Use of undefined constant picture - assumed 'picture' in C:\www\jetstar\starpick\rewards.php on line 34
[30-Jan-2012 23:36:49] PHP Notice: Use of undefined constant link - assumed 'link' in C:\www\jetstar\starpick\rewards.php on line 35
[30-Jan-2012 23:36:49] PHP Notice: Use of undefined constant name - assumed 'name' in C:\www\jetstar\starpick\rewards.php on line 36
[30-Jan-2012 23:36:49] PHP Notice: Use of undefined constant caption - assumed 'caption' in C:\www\jetstar\starpick\rewards.php on line 37
[30-Jan-2012 23:36:49] PHP 注意:使用未定义的常量消息 - 在 C:\www\jetstar\starpick\rewards.php 中第 33 行假定为“消息”
[30-Jan-2012 23:36:49] PHP 注意:使用未定义的常量图片 - 在 C:\www\jetstar\starpick\rewards.php 中第 34 行假定为“图片”
[30-Jan-2012 23:36:49] PHP 注意:使用未定义的常量链接 - 在 C:\www\jetstar\starpick\rewards.php 中第 35 行假定为“链接”
[30-Jan-2012 23:36:49] PHP 注意:使用未定义的常量名称 - 在 C:\www\jetstar\starpick\rewards.php 中第 36 行假定为“名称”
[30-Jan-2012 23:36:49] PHP 注意:使用未定义的常量标题 - 在 C:\www\jetstar\starpick\rewards.php 中第 37 行假定为“标题”
This is the codes i use
这是我使用的代码
$facebook->api("/me/feed", "post", array(
message => "I have won a ".$prizename,
picture => "http://i1172.photobucket.com/albums/r574/092810c/starpicklogo-1.png",
link => "https://apps.facebook.com/starpick/",
name => "StarPick",
caption => "Stand to Win Attractive Prizes!!!"));
回答by Marc B
You've forgotten quotes around your key names:
您忘记了键名周围的引号:
'message' => "I have won a ".$prizename,
^-------^--- missing
and the same for all the other parts of your array.
阵列的所有其他部分也是如此。
Keys in PHP MUST be quoted, otherwise they're assumed to be constants. PHP will politely treat undefined constants as unquoted strings, but will give you those warnings.
PHP 中的键必须被引用,否则它们将被假定为常量。PHP 会礼貌地将未定义的常量视为未加引号的字符串,但会给您这些警告。
回答by axiomer
The array keys should be put in quotes as well.
数组键也应该放在引号中。
The good code is:
好的代码是:
$facebook->api("/me/feed", "post", array(
"message" => "I have won a ".$prizename,
"picture" => "http://i1172.photobucket.com/albums/r574/092810c/starpicklogo-1.png",
"link" => "https://apps.facebook.com/starpick/",
"name" => "StarPick",
"caption" => "Stand to Win Attractive Prizes!!!"));