Monday, February 7, 2011
New Features of PHP 5.3.0
This release comes with major improvements as compared with the previous versions existing in PHP 5.x series.
PHP version 5.3.0 has many new features, as well as bug fixes (in this release over 140 bugs were repaired).
In the migration guide intended for the users of PHP 5.2.0 who want to upgrade to PHP 5.3.0,
there are explained the main differences between versions 5.2.0 and 5.3.0 of PHP.
Among the wide range of new features added in PHP 5.3.0, support for namespaces, Late Static Bindings, jump labels and native Closures (Lambda/Anonymous functions) was introduced. Two new magic methods are also supported in PHP 5.3.0: __callStatic and __invoke.
A garbage collection for cyclic references enabled by default and mysqlnd PHP native replacement for libmysql are optional. In the same time, now you are allowed to use dynamic access to static methods.
The code execution performance is improved. On the other hand, Windows support includes VC9 and experimental X64 binaries, as well as portability features to other compatible platforms.
Other key features of PHP 5.3.0 are:
-More consistent float rounding
-Deprecation notices are now handled via E_DEPRECATED (part of E_ALL) instead of the E_STRICT error level
-Several enhancements to enable more flexiblity in php.ini (and ini parsing in general)
-New bundled extensions: ext/phar, ext/intl, ext/fileinfo, ext/sqlite3, ext/enchant
The complete source code and Windows binaries of PHP 5.3.0 are available for free download,
Interface in PHP
Interface in PHP
PHP Interface:
PHP does not support multiple inheritance directly, to implement this we need Interface. It is much similar to Interface of Java.
In PHP, signature of the method are declared in the Interface body, and the body part of the method is implemented in derived class. Variables are declared as constant and it can not be changed in the child classes.
We use implement keyword to extend this kind of class, at the same time we can implement more than one interface and one interface can be implemented by another interface.
All methods declared in an interface must be public and the variables should be constant.
This is mandatory that we must declare the body part of the method in the derived class otherwise an error message will be generated.
Example:
interface Inter{
const a="This is constant value";
public function disp(); }
class A implements Inter{
function show(){
echo self::a."
";}
public function disp(){
echo "Inside the disp function";}}
$a=new A();
$a->show();
$a->disp();
?>
Output:
This is constant valueInside the disp function
Polymorphism in PHP
While thinking about a programming language deficiency, I rediscovered polymorphism. Overloading a function allows a function call to behave differently when passed variables of different type. I was trying to devise a method of simulating function overloading, because PHP does not support it. I considered implementing a function with an if-else statement ladder that tests the type of the actual argument and executes statements that correspond to the argument̢۪s type. This technique may ultimately result in a monolithic function or a function implementation that is too knowledgeable of multiple class hierarchies. Rethinking a problem that I was hoping to solve with function overloading allowed me to accept the lack of this language feature and think of other techniques.
There are two problems that arise from the if-else statement ladder approach. The implementation of such a function would require the function to have knowledge of every data type to be used with it. This problem can be extended to knowing class hierarchies, if subclassing is involved. This means that an introduction of a new data type to be processed by the function would require the function to be modified, which creates the possibility that the modification will break other existing code that relies on the function. The second problem is having the function̢۪s maintainer think about how the function should operate on the different data types that can be passed to it. This responsibility is better placed on the people who maintain the different data types.
One solution that deals with the problems in the if-else statement ladder is polymorphism. Polymorphism allows a set of heterogeneous elements to be treated identically. It is achieved through inheritance. In PHP, interface inheritance and implementation inheritance can be written explicitly through the use of interfaces and class extensions, respectively. Interfaces specify a class interface without providing an implementation. Classes from different class hierarchies can implement an interface, and in this way, it can be seen as different from abstract classes. When a class is defined to implement an interface, the language enforces a rule that the class implements all features of the interface. A method that operates on an interface will accept an object of any class that implements the interface, and it will function correctly.
Here is a toy example of interface inheritance, polymorphism, and PHP type hinting:
color = $color;
}
public function getColor()
{
return $this->color;
}
}
class Rectangle extends Shape implements HasArea
{
private $w;
private $h;
public function __construct( $color, $w, $h )
{
parent::__construct($color);
$this->w = $w;
$this->h = $h;
}
public function area()
{
return ($this->w * $this->h);
}
public function areaUnit()
{
if( $this->area() > 1 )
return "square meters";
else
return "square meter";
}
}
class Territory implements HasArea
{
private $name;
public function __construct( $name )
{
$this->name = $name;
/* not used in this example... */
}
public function area()
{
return 5;
}
public function areaUnit()
{
return "cities";
}
}
function outputArea( HasArea $ha )
{
echo "The area is: "
. " {$ha->area()} {$ha->areaUnit()}\n";
}
$HAs = array(
new Rectangle("red",2,3),
new Territory( "somename" )
);
foreach( $HAs as $HA )
{
outputArea( $HA );
}
?>
Type hints help the PHP interpreter enforce the restriction that outputArea()
operates only on objects of data types that implement the HasArea
interface. Rectangle
and Territory
are from unrelated class hierarchies. outputArea()
can operate on these classes, since these classes implement the HasArea
interface.
The explored method accomplishes only some of the features offered by function overloading. In the above example, outputArea()
was restricted to one argument. In some programming languages, a function can be overloaded on the number of arguments along with the types of those arguments and the order that those types appear in the argument list. This method, however, was useful in a problem I considered solving with function overloading.
Saturday, February 6, 2010
Characteristics of PHP
• Familiarity
• Simplicity
• Efficiency
• Security
• Flexibility
One final characteristic makes PHP particularly interesting: it’s free!
Programmers from many backgrounds will find themselves already accustomed to the PHP language. Many of the language’s constructs are borrowed from C and Perl, and in many cases PHP code is almost indistinguishable from that found in the typical C or Pascal program. This minimizes the learning curve considerably.
A PHP script can consist of 10,000 lines or one line: whatever you need to get the job done. There is no need to include libraries, special compilation directives, or anything of the sort. The PHP engine simply begins executing the code after the first escape sequence (). If the code is syntactically correct, it will be executed exactly as it is displayed.
EfficiencyEfficiency is an extremely important consideration for working in a multiuser environment such as the WWW. PHP 4.0 introduced resource allocation mechanisms and more pronounced support for object-oriented programming, in addition to session management features. Reference counting has also been introduced in the latest version, eliminating unnecessary memory allocation
SecurityPHP provides developers and administrators with a flexible and efficient set of security safeguards. These safeguards can be divided into two frames of reference: system level and application level.
System-Level Security SafeguardsPHP furnishes a number of security mechanisms that administrators can manipulate,providing for the maximum amount of freedom and security when PHP is properly configured. PHP can be run in what is known as safe mode, which can limit users’ attempts to exploit the PHP implementation in many important ways. Limits can also be placed on maximum execution time and memory usage, which if not controlled can have adverse affects on server performance. Much as with a cgi-bin folder, administrators can also place restrictions on the locations in which users can view and execute PHP scripts and use PHP scripts to view guarded server information, such as the passwd file.
Application-Level Security SafeguardsSeveral trusted data encryption options are supported in PHP’s predefined function set. PHP is also compatible with many third-party applications, allowing for easy-integration with secure ecommerce technologies. Another advantage is that the PHP source code is not viewable through the browser because the script is completely parsed before it is sent back to the requesting user. This benefit of PHP’s server-side architecture prevents the loss of creative scripts to users at least knowledgeable enough to execute a ‘View Source’.
Because PHP is an embedded language, it is extremely flexible towards meeting the needs of the developer. Although PHP is generally touted as being used in conjunction solely with HTML, it can also be integrated alongside languages like JavaScript, WML, XML, and many others. Additionally, as with most other mainstream languages, wisely planned PHP applications can be easily expanded as needed. Browser dependency is not an issue because PHP scripts are compiled entirely on the server side before being sent to the user. In fact, PHP scripts can be sent to just about any kind of device containing a browser, including cell phones, personal digital assistant (PDA) devices, pagers, laptops, not to mention the traditional PC. People who want to develop shell-based applications can also execute PHP from the command line.Since PHP contains no server-specific code, users are not limited to a specific and perhaps unfamiliar Web server. Apache, Microsoft IIs, Netscape Enterprise Server, Stronghold, and Zeus are all fair game for PHP’s server integration. Because of the various platforms that these servers operate on, PHP is largely platform independent, available for such platforms as UNIX, Solaris, FreeBSD, and Windows 95/98/NT.
Finally, PHP offers access to external components, such as Enterprise Java Beans and Win32 COM objects. These newly added features put PHP in the big league, truly enabling developers to scale PHP projects upward and outward as need be.
The open source development strategy has gained considerable notoriety in the software industry. The prospect of releasing source code to the masses has resulted in undeniably positive outcomes for many projects, perhaps most notably Linux, although the success of the Apache project has certainly been a major contributor in proving the validity of the open source ideal. The same holds true for the developmental history of PHP, as users worldwide have been a huge factor in the advancement of the PHP project.
PHP’s embracing of this open source strategy result in great performance gains for users, and the code is available free of charge. Additionally, an extremely receptive user community numbering in the thousands acts as “customer support,” providing answers to even the most arcane questions in popular online discussion groups.
PHP Frameworks
The most hyped framework. Why not; it’s by Zend which develops PHP itself. It has just got out of beta. You will also find it is rich with features too. It was also the fastest. No doubt it has all the corporate stuffs but I still felt it’s a bit tough. Just a little too much for most. It doesn’t have PHP 4 too. But it will definitely more provide support and professional code being backed by a corporate company. This is for those who want to build apps for big enterprises. They will have pro coders and will also be benefited from the components it provides.
CakePHP is a rapid development framework for PHP that provides an extensible architecture for developing, maintaining, and deploying applications. Using commonly known design patterns like MVC and ORM within the convention over configuration paradigm, CakePHP reduces development costs and helps developers write less code.

The Akelos PHP Framework is a web application development platform based on the MVC (Model View Controller) design pattern. Based on good practices, it allows you to: Write views using Ajax easily, Control requests and responses through a controller, Manage internationalized applications, Communicate models and the database using simple conventions.
Yii- PHP framework
Yii – a high-performance component-based PHP framework best for developing large-scale Web applications. Yii comes with a full stack of features, including MVC, DAO/ActiveRecord, I18N/L10N, caching, jQuery-based AJAX support, authentication and role-based access control, scaffolding, input validation, widgets, events, theming, Web services, and so on. Written in strict OOP, Yii is easy to use and is extremely flexible and extensible.
CodeIgniter is a powerful PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications. If you’re a developer who lives in the real world of shared hosting accounts and clients with deadlines, and if you’re tired of ponderously large and thoroughly undocumented frameworks.
Symfony is a full-stack framework, a library of cohesive classes written in PHP5. It provides an architecture, components and tools for developers to build complex web applications faster. Choosing symfony allows you to release your applications earlier, host and scale them without problem, and maintain them over time with no surprise. Symfony is based on experience. It does not reinvent the wheel: it uses most of the best practices of web development and integrates some great third-party libraries.
PRADOTM is a component-based and event-driven programming framework for developing Web applications in PHP 5. PRADO stands for PHP Rapid Application Development Object-oriented.
The Zoop Framework: PHP development without the suck. The Zoop Framework is inclusive, cooperating with and containing components integrated from some existing projects including Smarty, the Prototype JS Framework, and a number of Pear Modules.
xAjax is an open source PHP class library that allows to create quickly Ajax applications using HTML, CSS, JavaScript, and PHP.
Kohana is a PHP 5 framework that uses the model view controller architectural pattern. It aims to be secure, lightweight, and easy to use.
BlueShoes is a comprehensive application framework and content management system. It is written in the widely used web-scripting language PHP. BlueShoes offers excellent support for the popular MySQL database as well as support for Oracle and MSSQL.