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

Web Technologies-I



                   Notes         // comments.php
                                 // Navneet
                                 // ZetCode 2011

                                 /*
                                 comments.php

                                 Navneet
                                 ZetCode 2011
                                 */
                                 PHP also recognizes the comments from the C language.

                                 White Space
                                 White space in PHP is used to separate tokens in PHP source file. It is used to improve readability
                                 of the source code.
                                 public $isRunning;
                                 White spaces are required in some places. For example between the access specifier and the variable
                                 name. In other places, it is forbidden. It cannot be present in variable identifiers.
                                 $a=1;
                                 $b = 2;

                                 $c = 3;
                                 The amount of space put between tokens is irrelevant for the PHP interpreter.
                                 $a = 1;

                                 $b = 2;
                                 $c = 3;
                                 $d = 4;

                                 We can put two statements into one line or one statement into three lines. However, source code
                                 should be readable for humans. There are accepted standards of how to lay out your source code.

                                 Semicolon
                                 A semicolon is used to mark the end of a statement in PHP. It is mandatory.
                                 $a = 34;
                                 $b = $a * 34 34;

                                 echo $a;
                                 Here we have three different PHP statements. The first is an assignment. It puts a value into the
                                 $a variable. The second one is an expression. The expression is evaluated and the output is given
                                 to the $b variable. The third one is a command. It prints the $a variable.
                                 Variables

                                 A variable is an identifier, which holds a value. In programming we say that we assign a value
                                 to a variable. Technically speaking, a variable is a reference to a computer memory where the
                                 value is stored. In PHP language, a variable can hold a string, a number or various objects like a
                                 function or a class. Variables can be assigned different values over time.


        24                                LOVELY PROFESSIONAL UNIVERSITY
   25   26   27   28   29   30   31   32   33   34   35