Page 79 - Open Soource Technologies 304.indd
P. 79

Open Source Technologies



                   Notes         isset()  is  the only one of  the three language constructs  that accepts an arbitrary amount of
                                 parameters. Its accurate prototype is as follows:
                                 isset($var1, $var2, $var3, ...);

                                 It only returns true if all the variables have been defined; otherwise, it returns false. This is
                                 useful when you want to check if the required input variables for your script have really been
                                 sent by the client, saving you a series of single isset() checks.

                                 unset() “Undeclares” a previously set variable, and frees any memory that was used by it if
                                 no other variable references its value. A call to isset() on a variable that has been unset() returns
                                 false.

                                 For example:

                                 $name = ”John Doe”;
                                 unset($name);

                                 if (isset($name)) {

                                 print ’$name is set’;
                                 }

                                 This example will not generate any output, because isset() returns false.

                                 unset() can also be used on array elements and object properties similar to isset().
                                 6.1.1.3 Empty
                                 Empty() empty() may be used to check if a variable has not been declared or its value is false.
                                 This language construct is usually used to check if a form variable has not been sent or does not
                                 contain data. When checking a variable’s truth value, its value is first converted to a Boolean
                                 according to the rules in the following section, and then it is checked for true/false.
                                 For example:

                                 if (empty($name)) {

                                 print ‘Error: Forgot to specify a value for $name’;
                                 }

                                 This code prints an error message if $name doesn’t contain a value that evaluates to true.
                                 6.1.1.4 Superglobals

                                 As a general rule, PHP does not support global variables (variables that can automatically be
                                 accessed from any scope). However, certain special internal variables behave like global variables
                                 similar to other languages. These variables are called superglobals and are predefined by PHP
                                 for you to use. Some examples of these superglobals are:

                                 $_GET[]. An array that includes all the GET variables that PHP received from the client browser.








        74                                LOVELY PROFESSIONAL UNIVERSITY
   74   75   76   77   78   79   80   81   82   83   84