I been looking at plugin's source codes and be seeing the function isset function multiple times, I was not really sure what it was. So I looked it up, I didn't really understand it. What does it mean? Also how can this function be used in PocketMine?
isset returns true if the variable (or variables) passed to it is assigned. If a variable is assigned, it means that it contains some information.
So if I have a variable named $chocolate and equals a integer, EX: $chocolate = 7; It will return true?
`isset` is not a function. According to php.net, it is a language structure token. According to http://php.net/tokens, isset() is parsed as an individual token (T_ISSET) like return (T_RETURN), public (T_PUBLIC), function (T_FUNCTION), <?php (T_OPEN_TAG), etc, instead of a T_STRING like other functions. There are mutliple uses of `isset`: To check whether a variable is defined and not identical to (!==) null. A variable can be defined by: Normal variable assignment: PHP: $var = "value";var_dump(isset($var)); // bool(true)$var = false;var_dump(isset($var)); // bool(true)$var = null;var_dump(isset($var)); // bool(false) Parameters: PHP: function myFx($var){ return isset($var);}var_dump(myFx("string")); // bool(true)var_dump(myFx(false)); // bool(true)var_dump(myFx(null)); // bool(false) extract(): PHP: $array = array("a" => "b", "c" => false, "e" => null);extract($array);var_dump(isset($a)); // bool(true)var_dump(isset($c)); // bool(true)var_dump(isset($e)); // bool(false) Some other methods that I am not going to mention here, including reference parameter variables passed to functions. To check whether an array is associated with an element with a given key and the value is not identical to (!==) null. PHP: $array = array("a" => "b", "c" => false, "e" => null);var_dump(isset($array["a"])); // bool(true)var_dump(isset($array["c"])); // bool(true)var_dump(isset($array["e"])); // bool(false) To invoke offsetExists() in an implementation of ArrayAccess (but not offsetGet(), whether offsetExists() returns true or not). PHP: class MyClass implements \ArrayAccess{ public function offsetExists($k){ echo "Invoked offsetExists()", PHP_EOL; return true; } public function offsetGet($k){ echo "Invoked offsetGet()", PHP_EOL; return $k; // lol } public function offsetSet($k, $v){ echo "Invoked offsetSet()", PHP_EOL; } public function offsetUnset($k){ echo "Invoked offsetUnset()", PHP_EOL; }}$object = new MyClass;isset($object["anything"]) // Invoked offsetExists() To check if a class field is defined and not null and accessible (i.e. private (if you are in that class's context), protected (if you are in that class's or its subclass's context) or public (from all contexts)). PHP: class MyClass{ public $pu1, $pu2 = null, $pu3 = false; private $pr; public function issetTest(){ return isset($this->pr); }}$mc = new MyClass;var_dump( isset($mc->pu1), // bool(false) isset($mc->pu2), // bool(false) isset($mc->pu3), // bool(true) isset($mc->pr), // bool(false) $mc->issetTest() // bool(true)); Note that no undefined/inaccessible warnings are thrown inside the context of isset(). Another note is that although both $mc->pu1 (no initializer) and $mc->pu2 (initialized as null) return false in isset() without any warnings, an undefined field E_NOTICE level error is thrown if $mc->pu1 is accessed directly, while $mc->pu2 doesn't. Also, __isset() would be triggered instead if the class implements it. When getting more used to PHP, developers often forget that `$null = null; return isset($null);` returns false. So keep that in mind. Note that in PocketMine plugins, number 3 is rarely used except in NBT. For number 1, you don't use it unless you are more skilled with controlloing code flow. For number 2, it is very frequently used, especially in handling commands (checking whether an argument is given).