PHP Programming Language - Cultural View
PHP Programming Language - Cultural View PHP Programming Language - Cultural View
PHP 198 comment syntax: /* */ marks block and inline comments; // as well as # are used for one-line comments. [57] The echo statement is one of several facilities PHP provides to output text (e.g. to a web browser). In terms of keywords and language syntax, PHP is similar to most high level languages that follow the C style syntax. If conditions, for and while loops, and function returns are similar in syntax to languages such as C, C++, Java and Perl. Data types PHP stores whole numbers in a platform-dependent range. This range is typically that of 32-bit signed integers. Unsigned integers are converted to signed values in certain situations; this behavior is different from other programming languages. [58] Integer variables can be assigned using decimal (positive and negative), octal, and hexadecimal notations. Floating point numbers are also stored in a platform-specific range. They can be specified using floating point notation, or two forms of scientific notation. [59] PHP has a native Boolean type that is 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 and C++. [59] The null data type represents a variable that has no value. The only value in the null data type is NULL. [59] 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. [59] 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. [59] PHP also supports strings, which can be used with single quotes, double quotes, or heredoc syntax. [60] The Standard PHP Library (SPL) attempts to solve standard problems and implements efficient data access interfaces and classes. [61] Functions PHP has hundreds of base functions and thousands more via extensions. These functions are well documented on the PHP site; however, the built-in library has a wide variety of naming conventions and inconsistencies. PHP currently has no functions for thread programming, although it does support multiprocess programming on POSIX systems. [62] 5.2 and earlier Functions are not first-class functions and can only be referenced by their name, directly or dynamically by a variable containing the name of the function. [63] User-defined functions can be created at any time without being prototyped. [63] Functions can be defined inside code blocks, permitting a run-time decision as to whether or not a function should be defined. Function calls must use parentheses, with the exception of zero argument class constructor functions called with the PHP new operator, where parentheses are optional. PHP supports quasi-anonymous functions through the create_function() function, although they are not true anonymous functions because anonymous functions are nameless, but functions can only be referenced by name, or indirectly through a variable $function_name();, in PHP. [63] 5.3 and newer PHP gained support for closures. True anonymous functions are supported using the following syntax: function getAdder($x) { } return function ($y) use ($x) { }; return $x + $y;
PHP 199 $adder = getAdder(8); echo $adder(2); // prints "10" Here, getAdder() function creates a closure using parameter $x (keyword "use" forces getting variable from context), which takes additional argument $y and returns it to the caller. Such a function can be stored, given as the parameter to other functions, etc. For more details see Lambda functions and closures RFC [64] . The goto flow control device was made available in PHP 5.3 and is used as follows: function lock() { } $file = fopen("file.txt","r+"); retry: if(flock($file,LOCK_EX)) { } else fwrite($file, "Success!"); fclose($file); return 0; goto retry; When lock() is called, PHP opens a file and tries to lock it. retry:, the target label, defines the point to which execution should return if flock() is unsuccessful and the goto retry; is called. goto is restricted and requires that the target label be in the same file and context. Objects Basic object-oriented programming functionality was added in PHP 3 and improved in PHP 4. [2] Object handling was completely rewritten for PHP 5, expanding the feature set and enhancing performance. [65] In previous versions of PHP, objects were handled like value types. [65] The drawback of this method was that the whole object was copied when a variable was assigned or passed as a parameter to a method. In the new approach, objects are referenced by handle, and not by value. PHP 5 introduced private and protected member variables and methods, along with abstract classes and final classes as well as abstract methods and final methods. It also introduced a standard way of declaring constructors and destructors, similar to that of other object-oriented languages such as C++, and a standard exception handling model. Furthermore, PHP 5 added interfaces and allowed for multiple interfaces to be implemented. There are special interfaces that allow objects to interact with the runtime system. Objects implementing ArrayAccess can be used with array syntax and objects implementing Iterator or IteratorAggregate can be used with the foreach language construct. There is no virtual table feature in the engine, so static variables are bound with a name instead of a reference at compile time. [66] If the developer creates a copy of an object using the reserved word clone, the Zend engine will check if a clone() method has been defined or not. If not, it will call a default clone() which will copy the object's properties. If a clone() method is defined, then it will be responsible for setting the necessary properties in the created object. For convenience, the engine will supply a function that imports the properties of the source object, so that the programmer can start with a by-value replica of the source object and only override properties that need to be changed. [67]
- 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 and 174: PEAR 167 External links • The PEA
- Page 175 and 176: PHP syntax and semantics 169 Colon
- 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: PHP 197 Security The National Vulne
- 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
- Page 225 and 226: phpLDAPadmin 219 phpLDAPadmin Origi
- Page 227 and 228: phpMyAdmin 221 Release 0.9.0 Septem
- Page 229 and 230: phpMyAdmin 223 References [1] http:
- Page 231 and 232: phpPgAdmin 225 phpPgAdmin Stable re
- Page 233 and 234: PhpXCore 227 PhpXCore Stable releas
- Page 235 and 236: phpBB 229 Work on phpBB 3.0.x began
- Page 237 and 238: phpBB 231 phpBB3 phpBB3 is the curr
- Page 239 and 240: phpBB 233 The Development Team has
- Page 241 and 242: phpBB 235 phpBB Community phpBB is
- Page 243 and 244: phpBB 237 [45] phpBB (2009-07-29).
- Page 245 and 246: phplist 239 phplist Developer(s) Mi
- Page 247 and 248: phplist 241 Translations The admini
- Page 249 and 250: PHPmotion 243 Current status Versio
- Page 251 and 252: PhpWiki 245 See also • List of wi
- Page 253 and 254: Pimcore 247 Reviews and Articles
<strong>PHP</strong> 198<br />
comment syntax: /* */ marks block and inline comments; // as well as # are used for one-line comments. [57] The<br />
echo statement is one of several facilities <strong>PHP</strong> provides to output text (e.g. to a web browser).<br />
In terms of keywords and language syntax, <strong>PHP</strong> is similar to most high level languages that follow the C style<br />
syntax. If conditions, for and while loops, and function returns are similar in syntax to languages such as C, C++,<br />
Java and Perl.<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 />
Unsigned integers are converted to signed values in certain situations; this behavior is different from other<br />
programming languages. [58] Integer variables can be assigned using decimal (positive and negative), octal, and<br />
hexadecimal notations. Floating point numbers are also stored in a platform-specific range. They can be specified<br />
using floating point notation, or two forms of scientific notation. [59] <strong>PHP</strong> has a native Boolean type that is similar to<br />
the native Boolean types in Java and C++. Using the Boolean type conversion rules, non-zero values are interpreted<br />
as true and zero as false, as in Perl and C++. [59] The null data type represents a variable that has no value. The only<br />
value in the null data type is NULL. [59] Variables of the "resource" type represent references to resources from<br />
external sources. These are typically created by functions from a particular extension, and can only be processed by<br />
functions from the same extension; examples include file, image, and database resources. [59] Arrays can contain<br />
elements of any type that <strong>PHP</strong> can handle, including resources, objects, and even other arrays. Order is preserved in<br />
lists of values and in hashes with both keys and values, and the two can be intermingled. [59] <strong>PHP</strong> also supports<br />
strings, which can be used with single quotes, double quotes, or heredoc syntax. [60]<br />
The Standard <strong>PHP</strong> Library (SPL) attempts to solve standard problems and implements efficient data access<br />
interfaces and classes. [61]<br />
Functions<br />
<strong>PHP</strong> has hundreds of base functions and thousands more via extensions. These functions are well documented on the<br />
<strong>PHP</strong> site; however, the built-in library has a wide variety of naming conventions and inconsistencies. <strong>PHP</strong> currently<br />
has no functions for thread programming, although it does support multiprocess programming on POSIX systems. [62]<br />
5.2 and earlier<br />
Functions are not first-class functions and can only be referenced by their name, directly or dynamically by a<br />
variable containing the name of the function. [63] User-defined functions can be created at any time without being<br />
prototyped. [63] Functions can be defined inside code blocks, permitting a run-time decision as to whether or not a<br />
function should be defined. Function calls must use parentheses, with the exception of zero argument class<br />
constructor functions called with the <strong>PHP</strong> new operator, where parentheses are optional. <strong>PHP</strong> supports<br />
quasi-anonymous functions through the create_function() function, although they are not true anonymous functions<br />
because anonymous functions are nameless, but functions can only be referenced by name, or indirectly through a<br />
variable $function_name();, in <strong>PHP</strong>. [63]<br />
5.3 and newer<br />
<strong>PHP</strong> gained support for closures. True anonymous functions are supported using the following syntax:<br />
function getAdder($x)<br />
{<br />
}<br />
return function ($y) use ($x) {<br />
};<br />
return $x + $y;