PHP throwing “Use of Undefined Constant” Despite Quotes in String [closed]

你离开我真会死。 提交于 2021-02-05 12:18:05

问题


I have a PHP file wherein I'm trying to set a cookie; here is the code:

<?php
ini_set('display_errors', 1);
error_reporting(~0);
$coname = ‘logged’;
$coval = ‘false’;
setcookie($coname,$coval);
?>

Logged is the name of the cookie, false is the value. Right off the bat it's throwing:

Notice: Use of undefined constant ‘logged’ - assumed '‘logged’' in (path) on line 4
Notice: Use of undefined constant ‘false’ - assumed '‘false’' in (path) on line 5

It appears to be reading these strings as constants, then. Every resource I can find recommends solving this by enclosing the string in quotes, which I've tried with both single and double quotes to no avail. If anyone knows why the error persists, it would be a huge help. Thanks!


回答1:


You're using back- and forward-ticks instead of single quotation marks, so PHP is trying to interpret ‘logged’ and ‘false’ as constants, which aren't defined.

Try this instead:

<?php
ini_set('display_errors', 1);
error_reporting(~0);
$coname = 'logged';
$coval = 'false';
setcookie($coname,$coval);
?>


来源:https://stackoverflow.com/questions/43174434/php-throwing-use-of-undefined-constant-despite-quotes-in-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!