Google
 
   
Login
Username:

Password:


Lost Password?

Register now!
Search
Main Menu
service
top books
Polls
What do you think about php-deluxe.net?
Excellent!
Cool
Hmm..not bad
What the hell is this?
encyclopedia
recommendation
Freenet DSL
Who's Online
7 user(s) are online (7 user(s) are browsing encyclopedia)

Members: 0
Guests: 7

more...
partner

PHP

PHP is an .

Examples of PHP applications include PhpBB as well as MediaWiki. The PHP model can be seen as an alternative to Microsoft ASP.NET/C_sharp/Visual Basic .NET system, Macromedia s Macromedia_ColdFusion system, Sun Microsystems JavaServer Pages/Java programming language system, the Zope/Python programming language system, and to the mod_perl/Perl system.

PHP allows interaction with a large number of ) architectures exist as alternatives for those wishing to use Windows as their server operating system.

PHP is the result of the efforts of many contributors. It is licensed under a BSD License, the PHP license. Since version 4, it has been powered by the Zend engine.

=History=

PHP was originally designed as a small set of Perl scripts, followed by a rewritten set of CGI binaries written in C by the (PDO) and more performance enhancements taking advantage of the new Zend Engine II.

=Popularity=

PHP is currently one of the most popular server-side scripting systems on the Web. It has been widely adopted since the release of version 4.

One major part of PHP which has helped it become popular is that it is a very loose language; in particular, it is dynamic typing. That is, the rules are not as strict with variables—they do not have to be declared and they can hold any type of object. Arrays are heterogenous, meaning a single array can contain objects of more than one type.

According to Netcraft s April 2002 survey, PHP is now the most deployed server-side scripting language, running on around 9 million of the 37 million domains in their survey. This is confirmed by PHP s own figures, which show PHP usage (measured on a per-domain basis) growing at around 5% per month. In May 2003, almost 13 million domains were using PHP, based on the same source.[http://www.php.net/usage.php]

Due to PHP s popularity in the web space, a new breed of programmers emerged who are familiar only with PHP. This encouraged the development of a command line interface for PHP, as well as GUI libraries such as GTK and text mode libraries like Ncurses and Newt. This was a major step for PHP, because it helped move it from being a language used only for CGI to a general-purpose programming language. On the desktop it has been favored by some new programmers as a rapid prototyping environment.

=Code example=

Here is a Hello World code example (See [http://php.net/manual/en/language.basic-syntax.php Basic syntax] in the PHP manual):

Here is an example that prints out the lyrics for the song 99 Bottles of Beer :

Here s an alternate way of doing the previous example: (with simpler PHP code)

99 Bottles of Beer on the Wall

99 Bottles of Beer on the Wall

2 bottles of beer on the wall, 2 bottles of beer. Take one down, pass it around, 1 bottle of beer on the wall. 1 bottle of beer on the wall, 1 bottle of beer. Take one down, pass it around, No more bottles of beer on the wall. Go to the store, buy some more, 99 bottles of beer on the wall!

Notes: *PHP treats new lines as whitespace, in the manner of a free-form language (except when inside string quotes). A line of code is terminated only by a semicolon (;) except in a few special cases. [http://php.net/manual/en/language.basic-syntax.instruction-separation.php] *A period (.) concatenates strings together. [http://php.net/manual/en/language.types.string.php] *Variables are case sensitive and always have names that start with a dollar sign ($), and are evaluated inside double quotation marks ( ), but not inside single quotation marks ( ). Functions, such as plural(), and other expressions are not evaluated inside double quotes but can be added to strings using periods for concatenation.

Example:

$var = string . function() . rest of string ;

[http://php.net/manual/en/language.variables.php] *Although PHP allows both # and // for same line comments, it is generally preferred to use the C++-style // and not the Bourne Shell style #. [http://us2.php.net/manual/en/language.basic-syntax.comments.php] *Also seen above are the C style block comments starting with /* and ending with */ . All text within these tags are ignored *For output, this program uses echo. print and printf may also be used for this purpose.

=Libraries=

PHP includes a large number of free and open-source libraries with the core build. PHP is a fundamentally Internet-aware system with modules built in for accessing File transfer protocol servers, many database servers, embedded SQL libraries like embedded MySQL and SQLite, Lightweight Directory Access Protocol servers, and others. Many functions familiar to C programming language programmers such as the printf family are available in the standard PHP build.

PHP extension (computing)s exist which, among other features, add support for the Windows API, process management on Unix-like operating systems, cURL, and the ZIP (file format)/Gzip/Bzip2/RAR/LZF compression formats. Some of the more unusual features are on-the-fly Macromedia Flash generation, integration with Internet relay chat, and generation of dynamic images (where the content of the image can be changed). Some additional extensions are available via the PHP Extension Community Library (PECL).

This is the present list of all officially documented libraries:

(Source: [http://www.php.net/manual/en/ PHP.net manual])

=Object-oriented programming=

Up until version 3, PHP had no Object-oriented programming features. In version 3 basic object functionality was added. The same semantics were implemented in PHP 4 as well as pass-by-reference and return-by-reference for objects but the implementation still lacked the powerful and useful features of other object-oriented languages like C++ and Java.

In version 5, which was released in July 2004, PHP s object-oriented functionality has been very much enhanced and is more robust and complete. Here is a summary of some of the changes in PHP 5 (powered by [http://www.zend.com/php5/ Zend Engine II]):

; New Object Model : PHP s handling of objects has been completely rewritten, allowing for better performance and more features. In previous versions of PHP, objects were handled like primitive types (for instance integers and strings). The drawback of this method was that semantically the whole object was copied when a variable was assigned, or passed as a parameter to a method. In the new approach, objects are Reference (computer science) by handle, and not by value (one can think of a handle as an object s identifier). ; Private and Protected Members : PHP 5 introduces private and protected member variables, they allow you to define the Inheritance (object-oriented programming)#Constraints of inheritance-based design of class properties. ; Private and Protected Methods : Private and protected methods are also introduced. ; Abstract Classes and Methods : PHP 5 also introduces Class_(computer_science)#Abstract_and_Concrete_classes and abstract methods. An abstract method only declares the method s signature and does not provide an implementation. A class that contains abstract methods needs to be declared an abstract class. ; Interfaces : A class may implement an arbitrary list of interface (computer science). ; Object Cloning : If the developer asks to create a copy of an object by 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 all of the object s properties. If a __clone() method is defined, then it will be responsible to set the necessary properties in the created object. For convenience, the engine will supply a function that imports all of the properties from the source object, so that they can start with a by-value of the source object, and only override properties that need to be changed. ; Unified Constructors : PHP 5 introduces a standard way of declaring constructor methods by calling them by the name __construct(). ; Destructors : PHP 5 introduces a destructor concept similar to that of other object-oriented languages, such as C plus plus: When the last reference to an object is destroyed, the object s destructor (a class method named __destruct() that receives no parameters) is called before the object is freed from memory. ; Exceptions : PHP 4 had no exception handling. PHP 5 introduces an exception model similar to that of other programming languages.

More additions and examples of the additions mentioned above are available in the [http://php.net/manual/en/language.oop5.php Classes and Objects chapter] of the PHP 5 manual.

It should be noted that the static method and class variable features in Zend Engine 2 do not work the way some expect. There is no virtual table feature in the Engine, so the static variables are bound with a name at compile time instead of with a reference. This can lead to unexpected behavior, if you do not understand this.

Here is an example of creating an Object (computer science):

For more on PHP s Object-oriented programming abilities, see: *[http://us3.php.net/manual/en/language.oop.php PHP.net OOP Section] *[http://www.php-editors.com/articles/simple_php_classes.php Simple OOP Tutorial] *[http://www.phpfreaks.com/tutorials/48/0.php PHP Freaks OOP Tutorial] *[http://www.gurusnetwork.com/tutorial/oop_php/ Guru s Network OOP Tutorial] *[http://www.phppatterns.com Object Oriented Pattern for PHP] *[http://www.phpmvc.net PHP MVC Framework] *[http://www.mojavi.org PHP MVC Framework Mojavi] *[http://www.symfony-project.com PHP MVC Framework Symfony] *[http://www.xisc.com PRADO component-based framework]

=Scalability=

It s been suggested that PHP is a better alternative to JavaServer Pages/Java programming language because PHP scales better. Examples of the superior scalability of PHP over JavaServer Pages/Java programming language can be found on the Friendster transition and Yahoo! s decision to use PHP over JavaServer Pages/Java programming language.

=Criticisms=

Criticisms of PHP include those general criticisms ascribed to other scripting programming languages and Dynamic typing. In addition, specific criticisms of PHP include:

==Syntax==

*PHP does not enforce the declaration of variables, and variables that have not been initialized can have operations (such as concatenation) performed on them; however, an operation on an uninitialized variable does raise an E_NOTICE level error, errors that are hidden by default. This leads to security holes with register_globals (not on by default), as mentioned below. See also [http://php.net/manual/en/function.error-reporting.php error_reporting()]. *Within sections of the built-in function selection there is little or no consistency regarding argument order (examples: order of subject array and other data for array handling functions, order of needle and haystack in various search functions).

==Built-in functions==

*Built-in function names have no standard form, with some employing underscores (e.g. [http://www.php.net/strip_tags strip_tags], [http://www.php.net/html_entity_decode html_entity_decode]) while others do not (e.g. [http://www.php.net/stripslashes stripslashes], [http://www.php.net/htmlentities htmlentities]). Furthermore, some functions are verb_noun() while others are noun_verb() and some are prefixed_byModuleName while others use a module_suffix_scheme. Although all new functions do follow a naming standard, old names remain for backward compatibility reasons. *Some functions have inconsistent output. Statements like This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE, such as 0 or . can be found in [http://php.net/manual/en/function.strpos.php the documentation]. This is related to PHP s dynamic typing. A workaround is using strict (===) type checking as opposed to loose (==). See also the manual on [http://php.net/manual/en/language.types.type-juggling.php type juggling]. *The number of built-in functions is said to be too numerous, with many functions performing the same actions, but with just slightly different data, results, etc. This is said to make it difficult to program in the language without the frequent consultation of a reference work. *There are over 3,000 functions, sharing the same global namespace. Most functions are not enabled by default, but become available when PHP is linked against the required libraries. To mitigate this, function names are usually prefixed with their library name. *There is a magic quotes feature that inserts backslashes into user input strings. The feature was introduced to reduce code written by beginners from being dangerous (such as in SQL injection attacks), but some criticize it as a frequent cause of improperly displayed text or encouraging beginners to write PHP which is vulnerable to SQL-injection when used on a system with it turned off. (Always be sure to check for magic-quotes : [http://www.php.net/get_magic_quotes_gpc get_magic_quotes_gpc();] and to unset magic-quotes-runtime : [http://www.php.net/set_magic_quotes_runtime set_magic_quotes_runtime(0);].) Magic Quotes are turned off by default in PHP 5. For more information, see the security section in the [http://php.net/manual/en/security.magicquotes.php Magic Quotes chapter] of the PHP manual.

==Security==

*If [http://www.php.net/register_globals register_globals] is enabled in PHP s configuration file, users could cause harm by manipulating poorly written code. As of version [http://php.net/release_4_2_0.php 4.2.0] register_globals defaults to off. For more information, see the security section in the [http://php.net/manual/en/security.globals.php Using Register Globals chapter] of the PHP manual. *Other languages, such as ASP.NET, include functionality to detect and clean harmful cross-site scripting or other malicious code automatically, whereas PHP does not. See also [http://php.net/manual/en/function.strip-tags.php strip_tags()]. *In the majority of cases, Linux and Unix webservers with PHP installed (using mod_php) typically run PHP scripts as nobody , which can make file security in a shared hosting environment difficult. *PHP has no [http://gunther.web66.com/FAQS/taintmode.html variable tainting] mechanism (which is very useful for a language designed to accept and process untrusted input.)

==Miscellaneous==

*Error messages are said to be confusing, although this is a common criticism levelled at many programming languages. For further information, see the manual section on [http://php.net/manual/en/tokens.php PHP parser tokens]. *The many settings in the PHP interpreter s configuration file ( php.ini ) mean that code that works with one installation of PHP might not work with another. For example, if code is written to work with register_globals turned on, it won t work on another system that has register_globals turned off. This makes it necessary to write code that is cross-platform compatible by assuming that register_globals will be off and therefore calling a global variable with its prefix in front of its name, such as $_POST[ variable ], $_SERVER[ variable ] and $_COOKIE[ variable ]—not, simply, $variable. For more information, see the manual page on [http://php.net/manual/en/language.variables.external.php using external variables]. *Some PHP extensions use libraries that are not threadsafe, so rendering with Apache_HTTP_Server#Version_2.x s Multithreaded [http://httpd.apache.org/docs-2.0/mpm.html MPM] (multi-processing module) may cause crashes.

=Support=

PHP has a [http://www.php.net/docs.php formal development manual] that is maintained by the open source community. In addition, answers to most questions can often be found by doing a simple internet search. PHP users assist each other through various media such as chat, forums, newsgroups and PHP developer web sites. In turn, the PHP development team actively participates in such communities, garnering assistance from them in their own development effort (PHP itself) and providing assistance to them as well. There are many help resources available for the novice PHP programmer.

These resources include: *Online forums **[http://php.net/support.php Official PHP Support Page] **[http://www.phpfreaks.com PHP Freaks] **[http://forums.devshed.com Dev Shed] **[http://www.phpbuilder.com PHPBuilder] *Listservs/Mailing lists **[http://www.php.net/mailing-lists.php PHP mailing lists] **[news://news.php.net/ PHP.net s news server] *Newsgroups/Usenet **The group [http://groups.google.com/group/comp.lang.php comp.lang.php] *Chat / IRC **IRC channels #php and #phphelp on EFNet, IRCNet, DALnet and other networks. **Other IRC channels include [irc://irc.freenode.net/php #php] and [irc://irc.freenode.net/phpfreaks #phpfreaks] on freenode and [irc://irc.invisionize.com/phpcafe #phpcafe] on irc.invisionize.com. *User groups **[http://www.phpusergroups.org/ PHP user group registry] **[http://www.phpclasses.org/browse/group/ Directory of country specific PHP user groups], from the users of the PHP Classes site. **[http://www.nyphp.org/ New York PHP], the largest user group in North America (they maintain several active [http://www.nyphp.org/content/mailinglist/mlist.php mailing lists]). **California ***OCPHP - [http://ocphp.lucentminds.com/ Orange County PHP User Group](with a smile)

=See also=

*List of PHP applications.

=External links=

==PHP.net (official home of PHP)==

*[http://www.php.net/ Official PHP website] *Selected sub-pages of php.net: **[http://www.php.net/license/ PHP license information] **[http://www.php.net/usage.php PHP.net domain-based graph of PHP deployment] **[http://www.php.net/urlhowto.php When using the PHP.net website, access the content you would like to see quickly] *Selected sub-domains of php.net: **[http://pear.php.net/ PEAR: PHP Extension and Application Repository] **[http://pecl.php.net/ PECL: PHP Extension Community Library] **[http://smarty.php.net/ Smarty: Template Engine] **[http://gtk.php.net/ PHP-GTK extension providing an object-oriented interface to GTK+ classes and functions ] **[http://talks.php.net/ PHP Presents] and [http://conf.php.net/ PHP Conference Material Site] — Sites collecting slides of talks given by well known people from the PHP community. The former one is also known as pres2 (version 2 of the latter).

==Advocacy==

*[http://www.ukuug.org/events/linux2002/papers/html/php/ Experiences of Using PHP in Large Websites] *[http://public.yahoo.com/~radwin/talks/yahoo-phpcon2002.htm Making the Case for PHP at Yahoo!] — Michael J. Radwin, **Follow-up: [http://public.yahoo.com/~radwin/talks/one-year-of-php-oscon2003.htm One Year of PHP at Yahoo!] *[http://newsforge.com/newsforge/02/06/11/011243.shtmltid=5 Newsforge report] of Netcraft web host survey that says PHP is widely used *[http://www.onjava.com/pub/a/onjava/2003/10/15/php_scalability.html The PHP Scalability Myth] — Jack Herrington *[http://shiflett.org/archive/46 PHP Scales] — Chris Shiflett

==Books==

*[http://www.computer-books.us/php.php Computer-Books.us] — A collection of PHP books available for free download *[http://www.phpclasses.org/reviews PHP Book reviews] Reviews of PHP books and others of related interests

==Resources==

*Open Directory Project: **[http://www.dmoz.org/Computers/Programming/Languages/PHP/Scripts/Frameworks/ Frameworks] **[http://www.dmoz.org/Computers/Programming/Languages/PHP/Resources/ General resource sites] **[http://www.dmoz.org/Computers/Programming/Languages/PHP/Tools/ Integrated development environments, debuggers and other tools] **[http://www.dmoz.org/Computers/Programming/Languages/PHP/Tutorials/ Tutorials] *[http://www.blueshoes.org/en/developer/php_cheat_sheet/ PHP Cheat Sheet] — Compares with empty(), ==, === etc. *[http://www.phpclasses.org/ PHP Classes repository] - Ready-to-use PHP components in the form of classes of objects *[http://www.blueshoes.org/en/developer/syntax_exam/ PHP Syntax Test] — Do you know your PHP *[http://www.blueshoes.org/en/developer/php_bench/ PHP Benchmark] — Loops & Co. - how long does it take *[http://www.ilovejackdaniels.com/php/php-cheat-sheet/ PHP Cheat Sheet] — Printable single-page quick reference for PHP. *[http://www.php-editors.com/ PHP Editor Reviews] *[http://www.wiki.cc/php/Main_Page PHP Wiki] *[http://info.phpnexus.net PHP Wiki Documentation Project] *[http://forums.devnetwork.net/ PHP Developer s Network] *[http://www.hotuploads.com/ PHP Scripts Search Engine] *[http://wikicode.frihost.net/index.phptitle=Category:PHP Open-source PHP Scripts]

==Security==

*[http://www.sklar.com/page/article/owasp-top-ten The OWASP Top Ten Security Vulnerabilities] as applied to PHP. *[http://phpsec.org/ PHP Security Consortium] — International group of PHP experts dedicated to promoting secure programming practices. *[http://shiflett.org/php-security.pdf PHP Security Workbook] — A 55-page workbook on various security topics. *[http://www.phpwact.org/security/web_application_security WACT PHP Application Security Wiki] — The Web Application Component Toolkit s wiki page on PHP security resources. *[http://hardened-php.sourceforge.net Hardened PHP], a modification to PHP to protect it against common attacks such as cross site scripting

==Miscellaneous==

*Open Directory Project: [http://www.dmoz.org/Computers/Programming/Languages/PHP/ PHP] *How To: [http://www.sematopia.com/p=28 Install Apache, PHP, PEAR, MySQL & phpMyAdmin for Windows XP]