Biske94 Posted June 10, 2018 Report Share Posted June 10, 2018 (edited) 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 June 10, 2018 by Biske94 Quote Link to comment Share on other sites More sharing options...
Biske94 Posted June 19, 2018 Author Report Share Posted June 19, 2018 Answer: 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. Update To explain the differences between a NULL value and an undefined <?php //test 1 is defined, but has a value of null. isset will return false, use causes no error. $test1 = null; var_dump($test1); var_dump(isset($test1)); echo "\n----------\n\n"; //test2 is defined with a string value. isset will return true $test2 = "test"; var_dump($test2); var_dump(isset($test2)); echo "\n----------\n\n"; //test3 is not defined, isset returns false and use causes error. var_dump($test3); var_dump(isset($test3)); Which will output: NULL bool(false) ---------- string(4) "test" bool(true) ---------- Notice: Undefined variable: test3 in /in/Nmk0t on line 17 NULL bool(false) I hope this will help those who asked the same question as I Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.