Jump to content

Notice: Use of undefined constant? what does this mean


chasebadkids

Recommended Posts

It's also often caused by trying to access a variable but without a dollar sign or trying to access a hash key without placing the key in quotes.

<?php
$foo = 'bar'; //ok
echo foo; //undefined constant, common typo
$hash = array('foo'=>'bar');
echo $hash['foo']; //ok
echo $hash[foo]; //undefined constant, foo is a string
?>

Link to comment
Share on other sites

As KrisNz says it'll be to do with using constants inside arrays.

e.g.

 

echo $hash[foo];

 

Because PHP is a lenient language you're lucky, and because it doesn't recognise foo as a constant it instead converts it to a string for you, thus resolving your problem. Although you are still getting warnings probably because you turned them on.

Link to comment
Share on other sites

This is going to make a couple people on this forum yell at me but...

 

If you find there are lot's of these Notice errors, just turn Notices off for error_reporting: http://us.php.net/error-reporting. Notices are off by default in PHP, and if you didn't write the code, it's *usually* not worth the hassle of trying to fix someone else's poor coding. As long as the site works as expected with them off....

Link to comment
Share on other sites

I'm with Barand.

 

If a publicly released script was not written with enough care or by someone with enough programming experience to use correct syntax, then just think of all the other problems that could be present in it that would allow code/sql/email injection or un-caught validation and error checking that will either display errors to the visitor or result in broken or blank pages.

 

Using $today[month] vs $today['month'] is just basic abc123 syntax, it is not even programming logic. Could the actual program logic be worth much?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.