Solution PHP Notice: Use of undefined constant x — assumed ‘x’

I once noticed the following notification when writing a PHP script:

PHP Notice:  Use of undefined constant uid - assumed 'uid' in /scripts/file.php on line 31
PHP Notice:  Use of undefined constant value - assumed 'value' in /scripts/file.php on line 32


The code was:

while($Row = mysqli_fetch_array($Result))
{
$uid = $Row[uid];
$phone =$Row[value];
…

To remove the notification, I quotes all values:

$uid = $Row['uid'];
$phone =$Row['value'];
...

Also, this notification may appear when we created a variable and indicated it after “echo” without the “$” symbol, for example:

$test = "123";
echo test;

And you need:

echo $test;

Join the Conversation

1 Comment

Leave a Reply