PHP Programming Language - Cultural View
PHP Programming Language - Cultural View PHP Programming Language - Cultural View
PHP syntax and semantics 168 PHP syntax and semantics The syntax of the PHP programming language is the set of rules that defines how a PHP program will be written and interpreted. Overview PHP only parses code within its delimiters. Anything outside its delimiters is sent directly to the output and not parsed by PHP. The most common delimiters are , respectively open and close delimiters. style delimiters are also always available, so these two forms are the most portable. The first form of delimiters, , in XHTML and other XML documents, creates correctly formed XML 'processing instructions'. [1] Therefore, in either of these two cases, the resulting mixture of PHP and other markup is well-formed, and so probably valid, as XML and XHTML on the server before PHP processing. This may be helpful if the source code documents ever need to be processed in other ways during the life of the software. Short opening tags (
PHP syntax and semantics 169 Colon Syntax PHP offers an alternative syntax to the standard curly-brace syntax. This syntax is called colon syntax and affects the following control structures: if, while, for, foreach, and switch. [9] The syntax varies only slightly from the curly-brace syntax. In each case the opening brace ({) is replaced with a colon (:) and the close brace is replaced with endif;, endwhile;, endfor;, endforeach;, or endswitch;, respectively. [10] An example of the syntax for an if/elseif statment is as follows: [9] if (condition) : // code here elseif (condition) : else : endif; // code here // code here Data types PHP stores whole numbers in a platform-dependent range. This range is typically that of 32-bit signed integers. Integer variables can be assigned using decimal (positive and negative), octal and hexadecimal notations. Real numbers are also stored in a platform-specific range. They can be specified using floating point notation, or two forms of scientific notation. [11] PHP has a native Boolean type, named "boolean", similar to the native Boolean types in Java and C++. Using the Boolean type conversion rules, non-zero values are interpreted as true and zero as false, as in Perl. [11] The null data type represents a variable that has no value. The only value in the null data type is NULL. [11] Variables of the "resource" type represent references to resources from external sources. These are typically created by functions from a particular extension, and can only be processed by functions from the same extension. Examples include file, image and database resources. [11] Arrays can contain elements of any type that PHP can handle, including resources, objects, and even other arrays. Order is preserved in lists of values and in hashes with both keys and values, and the two can be intermingled. Objects can syntactically be used as Arrays. [11] Functions PHP has hundreds of base functions and thousands more from extensions. Functions are not first-class functions and can only be referenced by their name prior to PHP version 5.3.0, whereas PHP 5.3.0 introduces closures. [12] User-defined functions can be created at any time and without being prototyped. [12] Functions can be defined inside code blocks, permitting a run-time decision as to whether or not a function should be defined. There is no concept of local functions. Function calls must use parentheses with the exception of zero argument class constructor functions called with the PHP new operator, where parentheses are optional. An example function definition is the following:
- Page 123 and 124: Mambo (software) 117 • The former
- Page 125 and 126: Mambo (software) 119 [19] "NYS Depa
- Page 127 and 128: Merlintalk 121 • 2008: Released m
- Page 129 and 130: MetaBB 123 References [1] http://fo
- Page 131 and 132: Midgard (software) 125 Midgard (sof
- Page 133 and 134: Midgard (software) 127 See also •
- Page 135 and 136: Midgard Lite 129 Midgard Lite Midga
- Page 137 and 138: MindTouch Deki 131 History MindTouc
- Page 139 and 140: MindTouch Deki 133 Users of the Com
- Page 141 and 142: Moodle 135 Moodle Moodle course scr
- Page 143 and 144: Moodle 137 show, it has been cited
- Page 145 and 146: Moodle 139 See also • Learning ma
- Page 147 and 148: MyBB 141 MyBB A default installatio
- Page 149 and 150: MyBB 143 free software released und
- Page 151 and 152: NETSOFTWARE 145 Structure of compan
- Page 153 and 154: User:Nichescript/Affiliate Niche Sr
- Page 155 and 156: Ning (website) 149 Feature modifica
- Page 157 and 158: Ning (website) 151 [11] http://blog
- Page 159 and 160: NolaPro 153 In May 2005, NolaPro wa
- Page 161 and 162: ocPortal 155 ocPortal Developer(s)
- Page 163 and 164: ocPortal 157 Version history • Ma
- Page 165 and 166: Open Realty 159 References [1] Open
- Page 167 and 168: Opus (content management system) 16
- Page 169 and 170: osCommerce 163 osCommerce Developer
- Page 171 and 172: osCommerce 165 Branches Distributed
- Page 173: PEAR 167 External links • The PEA
- Page 177 and 178: PHP syntax and semantics 171 } { $d
- Page 179 and 180: PHPClasses repository 173 PHPClasse
- Page 181 and 182: PHPDoc 175 markup for display forma
- Page 183 and 184: PHPDoc 177 The text that marks this
- Page 185 and 186: PHPDoc 179 @static Documents a stat
- Page 187 and 188: PHPEclipse 181 Further reading •
- Page 189 and 190: User:Papagel/EFront (eLearning soft
- Page 191 and 192: Phalanger (compiler) 185 Phalanger
- Page 193 and 194: pHAML 187 pHAML Developer(s) David
- Page 195 and 196: pHAML 189 Hello World Hello W
- Page 197 and 198: Phoca Gallery 191 References [1] ht
- Page 199 and 200: PHP 193 PHP Paradigm imperative, ob
- Page 201 and 202: PHP 195 Licensing PHP is free softw
- Page 203 and 204: PHP 197 Security The National Vulne
- Page 205 and 206: PHP 199 $adder = getAdder(8); echo
- Page 207 and 208: PHP 201 Speed optimization PHP sour
- Page 209 and 210: PHP 203 [18] "GoPHP5" (http://gophp
- Page 211 and 212: HipHop for PHP 205 HipHop for PHP D
- Page 213 and 214: PHP-GTK 207 PHP-GTK Developer(s) An
- Page 215 and 216: PHP-GTK 209 External links • Offi
- Page 217 and 218: PHP-Nuke 211 • News—Manages new
- Page 219 and 220: Php4delphi 213 Php4delphi Appeared
- Page 221 and 222: phpDocumentor 215 phpDocumentor Sta
- Page 223 and 224: PhpGedView 217 PhpGedView can be ex
<strong>PHP</strong> syntax and semantics 169<br />
<br />
Colon Syntax<br />
<strong>PHP</strong> offers an alternative syntax to the standard curly-brace syntax. This syntax is called colon syntax and affects the<br />
following control structures: if, while, for, foreach, and switch. [9] The syntax varies only slightly from the<br />
curly-brace syntax. In each case the opening brace ({) is replaced with a colon (:) and the close brace is replaced with<br />
endif;, endwhile;, endfor;, endforeach;, or endswitch;, respectively. [10] An example of the syntax for an if/elseif<br />
statment is as follows: [9]<br />
if (condition) :<br />
// code here<br />
elseif (condition) :<br />
else :<br />
endif;<br />
// code here<br />
// code here<br />
Data types<br />
<strong>PHP</strong> stores whole numbers in a platform-dependent range. This range is typically that of 32-bit signed integers.<br />
Integer variables can be assigned using decimal (positive and negative), octal and hexadecimal notations. Real<br />
numbers are also stored in a platform-specific range. They can be specified using floating point notation, or two<br />
forms of scientific notation. [11] <strong>PHP</strong> has a native Boolean type, named "boolean", similar to the native Boolean types<br />
in Java and C++. Using the Boolean type conversion rules, non-zero values are interpreted as true and zero as false,<br />
as in Perl. [11] The null data type represents a variable that has no value. The only value in the null data type is<br />
NULL. [11] Variables of the "resource" type represent references to resources from external sources. These are<br />
typically created by functions from a particular extension, and can only be processed by functions from the same<br />
extension. Examples include file, image and database resources. [11] Arrays can contain elements of any type that<br />
<strong>PHP</strong> can handle, including resources, objects, and even other arrays. Order is preserved in lists of values and in<br />
hashes with both keys and values, and the two can be intermingled. Objects can syntactically be used as Arrays. [11]<br />
Functions<br />
<strong>PHP</strong> has hundreds of base functions and thousands more from extensions. Functions are not first-class functions and<br />
can only be referenced by their name prior to <strong>PHP</strong> version 5.3.0, whereas <strong>PHP</strong> 5.3.0 introduces closures. [12]<br />
User-defined functions can be created at any time and without being prototyped. [12] Functions can be defined inside<br />
code blocks, permitting a run-time decision as to whether or not a function should be defined. There is no concept of<br />
local functions. Function calls must use parentheses with the exception of zero argument class constructor functions<br />
called with the <strong>PHP</strong> new operator, where parentheses are optional.<br />
An example function definition is the following:<br />