Php Article Index for
Php
Shopping
PHP
Articles about
Php
Website Links For
Php
 

Information About

Php





Programming Information

  Name PHP
  Designer Rasmus Lerdorf
  Developer The PHP Group
  Latest Release Version 524
  Latest Release Date 30 Aug 2007
  Operating System Cross-platform
  Paradigm Imperative , Object-oriented
  Year 1995
  Typing Dynamic , Weak
  License PHP License
  Website http://phpnet/
  Influenced By C , Perl <br /> Java , C++ , Python


PHP is a Reflective Programming Language originally designed for producing Dynamic Web Page s.1 PHP is used mainly in Server-side Scripting , but can be used from a Command Line Interface or in standalone Graphical Applications . Textual User Interfaces can also be created using Ncurses . PHP is a Recursive Acronym for "PHP: Hypertext Preprocessor".

The main implementation is produced by The PHP Group and released under the PHP License . It is considered to be Free Software by the Free Software Foundation . This implementation serves to define a '' De Facto '' standard for PHP, as there is no Formal Specification .

Currently, two major versions of PHP are being actively developed: 5.x and 4.4.x; on July 13 , 2007 , the PHP group announced that active development on PHP4 will cease by December 31 , 2007 , however, critical security updates will be provided until August 8 , 2008 . php.net 2007 news archive


HISTORY

PHP was written as a set of CGI binaries in the C Programming Language by the Danish/Greenlandic programmer Rasmus Lerdorf in 1994, to replace a small set of Perl scripts he had been using to maintain his Personal Homepage .2 Lerdorf initially created PHP to display his Résumé and to collect certain data, such as how much traffic his page was receiving. ''Personal Home Page Tools'' was publicly released on 8 June 1995 after Lerdorf combined it with his own ''Form Interpreter'' to create ''PHP/FI'' (this release is considered PHP version 2).3

testing. Public testing of PHP 3 began and the official launch came in June 1998. Suraski and Gutmans then started a new rewrite of PHP's core, producing the Zend Engine in 1999.4 They also founded Zend Technologies in Ramat Gan , Israel, which actively manages the development of PHP.

In May 2000 , PHP 4, powered by the Zend Engine 1.0, was released. The most recent update released by The PHP Group, is for the older PHP version 4 code branch which, as of May 2007 , is up to version 4.4.7. PHP 4 will be supported by security updates until 8 August 2008 php.net 2007 news archive .

On July 13 2004 , PHP 5 was released powered by the new Zend Engine II. PHP 5 included new features such as:http://www.onlamp.com/pub/a/php/2004/07/15/UpgradePHP5.html


The latest stable version, PHP 5.2.4 , was released on Aug 30 , 2007 .


USAGE


PHP generally runs on a Web Server , taking PHP code as its input and creating Web pages as output. However, it can also be used for Command-line scripting and Client-side GUI applications. PHP can be deployed on most Web Server s and on almost every Operating System and Platform free of charge. The PHP Group also provides the complete source code for users to build, customize and extend for their own use.

PHP primarily acts as a Filter . The PHP program takes input from a file or stream containing text and special PHP instructions and outputs another stream of data for display.

From PHP 4, the PHP parser Compiles input to produce Bytecode for processing by the Zend Engine , giving improved performance over its Interpreter predecessor. PHP 5 uses the Zend Engine II.


Server-side scripting

Originally designed to create dynamic web pages, PHP's principal focus is Server-side Scripting .
While running the PHP Parser with a Web Server and Web Browser , the PHP model can be compared to other server-side scripting languages such as Microsoft 's ASP.NET system, Sun Microsystems ' JavaServer Pages , Mod_perl and the Ruby On Rails framework, as they all provide dynamic content to the Client from a web server. To more directly compete with the "framework" approach taken by these systems, Zend is working on the Zend Framework - an emerging (as of June 2006) set of PHP building blocks and best practices; other PHP Frameworks along the same lines include CakePHP , PRADO and Symfony .

The LAMP architecture has become popular in the Web industry as a way of deploying inexpensive, reliable, scalable, secure web applications. PHP is commonly used as the ''P'' in this bundle alongside Linux , Apache and MySQL , although the ''P'' can also refer to Python or Perl . PHP can be used with a large number of Relational Database Management System s, runs on all of the most popular web servers and is available for many different Operating System s. This flexibility means that PHP has a wide installation base across the Internet; over 19 million Internet domains are currently hosted on servers with PHP installed.http://php.net/usage.php

Examples of popular server-side PHP applications include PhpBB , WordPress , and MediaWiki .


Command-line scripting


PHP also provides a Command Line Interface SAPI for developing shell and desktop applications, daemons, log parsing, or other system administration tasks. PHP is increasingly used on the command line for tasks that have traditionally been the domain of Perl , Python , Awk , or Shell Script ing.


Client-side GUI applications


PHP provides bindings to GUI libraries such as GTK+ (with PHP-GTK ), Qt with PHP-Qt and text mode libraries like Ncurses in order to facilitate development of a broader range of Cross-platform GUI applications.


SYNTAX

The usual Hello World code example for PHP is:


echo 'Hello, World!';
?>


PHP only parses code within its Delimiter s, such as . Anything outside its delimiters is sent directly to the output and not parsed by PHP. The example above is equivalent to the following text (and indeed is converted into this form):

Hello, World!

The primary use of this is to allow PHP statements to be embedded within HTML documents, for example:




<?php echo ;?>


Hello




Variables are prefixed with a Dollar Symbol and a Type does not need to be specified in advance. Unlike function and class names, variable names are case sensitive. Both double-quoted ("") and Heredoc strings allow the ability to embed the variable's value into the string.

PHP treats new lines as Whitespace , in the manner of a Free-form Language (except when inside string quotes). Statements are terminated by a semicolon, except in a few special cases.

  • ---/ which serves as block comments, and // as well as # which is used for inline comments.


It should be noted that many examples use the print function instead of the echo function; the two are practically identical, and one may decide which one to use based on his personal preference.


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 .

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 can be interpreted as true and zero as false, as in Perl.


There are eight data types in PHP:
# Integer
# Double
# Boolean
# String
# Object
# Array
# Null
# Resource

The null data type represents a variable that has no value. The only value in the null data type is ''NULL''.

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.

Array s support both numeric and string indices, and are Heterogeneous . 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


Basic Object-oriented Programming functionality was added in PHP 3. Handling of objects was completely rewritten for PHP 5, allowing for better performance and more features. In previous versions of PHP, objects were handled like Primitive Type s. 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 Variable s and methods, along with Abstract Classes and Abstract Method s. It also introduced a standard way of declaring Constructors and Destructors similar to that of other object-oriented languages, such as C++, and an Exception Handling model similar to that of other programming languages.

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 Variable s are bound with a name at compile time instead of with a reference.


class foo extends bar
{
function __construct()
{
}
public static function mystaticfunc()
{
}
}


The above very basic example shows how to define a class, foo, that inherits from class bar.
Additionally, the function, mystaticfunc, is a public static function that is called with foo::mystaticfunc();.

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 for setting 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.


RESOURCES


Libraries

See Also: List of PHP 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 FTP servers, many database servers, embedded SQL libraries such as embedded MySQL and SQLite , LDAP servers, and others. Many functions familiar to C programmers such as those in the Stdio family are available in the standard PHP build.


Extension


PHP allows developers to write Extension s in C to add functionality to the PHP language. These can then be compiled into PHP or loaded dynamically at runtime. Extensions have been written to add support for the Windows API , process management on Unix-like Operating System s, multibyte strings ( Unicode ), CURL , and several popular Compression Formats . Some more unusual features include integration with Internet Relay Chat , dynamic generation of images and Adobe Flash content, and even Speech Synthesis . The PHP Extension Community Library (PECL) project is a repository for extensions to the PHP language.


Source code encoders, optimizers and accelerators


As with many scripting languages, PHP scripts are normally kept as human-readable source code, even on production webservers. While this allows flexibility, it can raise issues with security and performance.

Encoders hinder source code Reverse Engineering . Encoders fall broadly into two types; those that hide source code and those that compile code into "optcode" . The downside of this latter approach is that a special extension has to be installed on the server in order to run encoded scripts, however the approach of encoding compiled code and use of an extension offers typically the best performance, security and opportunity for additional features that may be useful for developers. Compiled code solutions may exploit the potential for increased security through the use of their own execution engine, although some simpler solutions rely on the regular PHP engine to execute the compiled code. The most commonly used packages for source code protection are from Zend Technologies and IonCube Ltd.

Code optimizers improve the quality of the compiled code by reducing its size and making changes that can reduce the execution time and improve performance. The nature of the PHP Compiler is such that there are often many opportunities for Code Optimization .

Accelerators offer performance gains by Caching the compiled form of a PHP script in Shared Memory to avoid the overhead of Parsing and Compiling the code every time the script runs. They may also perform Code Optimization to provide increased execution performance. Both commercial (e.g. Zend Platform) and open source accelerators (e.g. xcache, eAccelerator, APC) are available.


Debuggers and profilers


Debugger s and Profiler s allow developers to analyze running PHP code for potential and noted Software Bug s and bottlenecks. Examples of such software for PHP include APD and Xdebug .


Templating engines


Templating engines provide Macro s that allow PHP applications to uniformly identify common variables. One popular templating engine is Smarty . PHP itself makes a good templating engine.


PEAR


The PHP Extension And Application Repository (PEAR) project aims to provide reusable libraries and components for PHP development. PEAR projects are usually written in PHP code using the Object-oriented Programming paradigm.


SUPPORT


PHP has a formal development manual that is maintained by the Free Software Community . In addition, answers to many 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 resourceshttp://php.net/support available for the novice PHP programmer.


CRITICISM


Criticisms of PHP include those ascribed to Scripting Language s and Dynamically Typed Language s in general, such as low performance for general-purpose computation. The list below includes criticisms specific to PHP, some of which have been rectified in recent versions.
  • PHP originally inserted data received over the network directly into the Global namespace register_globals , leading to confusion between trusted and untrusted data, and unnecessary potential for security holes in PHP applications. This behavior was turned off by default from version 4.2.0 released in April 2002. PHP Manual: Chapter 29. Using Register Globals However, this feature is still being used by some legacy applicationshttp://www.oscommerce.info/kb/osCommerce/Installation_and_Upgrades/46.

  • PHP has traditionally used features such as " Magic_quotes_gpc " and "magic_quotes_runtime" which attempt to escape apostrophes (') and quotes (") in strings in the assumption that they will be used in databases, to prevent SQL Injection attacks. This leads to confusion over which data is escaped and which is not, and to problems when data is not in fact used as input to a database. Rasmus Lerdorf's thoughts about PHP6

  • PHP does not have complete native support for )

  • PHP does not enforce the declaration of variables prior to their use, and variables which have not been initialized can have operations (such as Concatenation ) performed on them; an operation on an uninitialized variable raises an E_NOTICE level error, but this is hidden by default.

  • PHP has no Namespace support, which leads to a very large amount of globally available functions that can easily number into the thousands.

  • PHP's dynamic type conversion could potentially cause problems. Variable types in PHP, although they exist, are transparent to the programmer. Some may consider this a feature, as a variable can change from a Number to a String and back again without extra lines of code. However, variable type errors are not detected at compile-time, and the dynamic-typing behavior lacks full predictability.

  • The standard function library lacks internal consistency. Many functions perform relatively similar actions and have different name standards and argument orders. For example:

  • --- Argument consistency: strpos(, ) vs. in_array(, )

  • --- Naming convention: both of these work case-insensitively strcasecmp() vs. stristr() but the former indicates this with "case" while the later does with "i"

  • --- Function Name Consistency : strpos() vs. str_replace()

  • Functions are not First-class Object s. This requires referencing functions by strings and object methods as a two-element array of the object and method name as a string. Consequently, Anonymous Function s are also referenced by string.

  • Lack of , 2007

  • Some portability issues with 32-bit and 64-bit integers, and sometimes unsigned integers get converted to signed values.



RELEASE HISTORY OF MAJOR VERSIONS



FUTURE DEVELOPMENT


PHP 6, in development as of July 2007, aims to address some of PHP 5's shortcomings.http://www.php.net/~derick/meeting-notes.html

  • Namespace support will be added.

  • Native Unicode support will be added.

  • The magic_quotes option will be removed.

  • The HTTP_---_VARS global variables will be removed.

  • The register_globals option will be removed.

  • The safe_mode option will be removed.

  • Late static binding will be added.



SEE ALSO




REFERENCES



FURTHER READING




EXTERNAL LINKS