Jump to content
Lizard Wizard Coding Club

Recommended Posts

What does mean that variable is set or not set? (in PHP or general)

Does that means:

  • // no var declared
  • $var;
  • $var = 'Some fancy string';
  • $var = ""; //(empty string)

I dont know all fancy terms, but I do know when variable is defined, declared and all that, but I dont know what variable is set means.

Thanks in advance, nerdz!

Edited by Biske94
Link to post
Share on other sites
  • 2 weeks later...



isset() is a function in PHP that will return true if the variable, in this case, $var has been assigned a value. If the variable has been created but nothing assigned, has the value of null or undefined, it will return false. basically, isset($var) says is this variable safe to use or not. 


To explain the differences between a NULL value and an undefined

//test 1 is defined, but has a value of null. isset will return false, use causes no error.
$test1 = null;

echo "\n----------\n\n";

//test2 is defined with a string value. isset will return true
$test2 = "test";

echo "\n----------\n\n";

//test3 is not defined, isset returns false and use causes error.

Which will output:



string(4) "test"


Notice: Undefined variable: test3 in /in/Nmk0t on line 17


I hope this will help those who asked the same question as I :)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...