PDA

View Full Version : Check if datastore entry exists?


JamesAB
05-19-2015, 04:25 PM
I thought I saw the answer to this yesterday while searching the forums, but now I can't find the post. Now I can't fine the post.

What is the best way to test if a datastore entry exists before trying to use the data that is supposed to be there?

Thanks,
James

--------------- Added 1432064018 at 1432064018 ---------------

I think I found it.
Does this look right?

if ($vbulletin->datastore_item !== null)

kh99
05-19-2015, 06:15 PM
Man, I just read that whole section on NULL vs isset() vs empty() a few weeks ago and I already can't remember. I think what you have is right because IIRC I don't think there's any practical difference between a variable set to NULL and an unset variable.

JamesAB
05-19-2015, 09:16 PM
I got that code bit from the first post in this thread:
https://vborg.vbsupport.ru/showthread.php?t=98047

kh99
05-19-2015, 09:35 PM
Hmm...I guess at some point it used to be separate from $vbulletin (or $vbulletin didn't exist yet), but I wonder why they changed from isset() to !== NULL? Anyway, I guess that'll work.