12 Sept 2013

Php 5.4 : New Features


php-development-design

In this article, I talked concerning PHP's stubborn, function-over-form approach to resolution the "Web problem" and also the fight to keep things easy. we were obtaining near releasing PHP getting.0 at the time. currently here we are nearly a decade later with a shiny new PHP 5.4.0 release, and whereas much is going on during that point, there are several things that haven't modified at all.

One issue that hasn't modified is that the ecosystem is as vital as it ever was. resolution the web drawback is concerning way more than selecting a scripting language. it's concerning the complete ecosystem around it. The LAMP stack has been strong for nearly 15 years currently and it's still popular, however we are starting to see strong alternatives. PHP-FPM with nginx has been gaining quality speedily as a result of the much improved support beginning in PHP 5.3 and further efficient in 5.4. The M, or database, a part of the stack is additionally starting to become way more diverse than it had been 8 years ago. the varied NoSQL solutions and MySQL Cluster give a richer set of choices than simply throwing everything into a MyISAM table.
A number of attention-grabbing technologies have appeared and PHP extensions are written to form them easily accessible. one in all my favorites is libevent, that you can use to write superior event-driven applications in PHP. Another is ZeroMQ, that is a high-level socket library. very similar to SQLite removed any and all need to ever write another raw file format and associated programme, ZeroMQ has removed any reason to play with socket protocols and associated socket handling code. you can even mix libevent with ZeroMQ for an amazing, superior, standalone event-driven server. (See this example if you're fascinated by that.) I also like SVM (Support Vector Machine), a machine-learning algorithm that you simply can throw plenty of issues at without having to become a machine-learning geek.

There are variety of extensions that became well-established over the last few years. Gearman, especially, has become popular and shows up as a part of the common stack folks deploy. Gearman enables you to dispatch jobs to be done by staff asynchronously. The staff can be unfolded over several servers and that they can even further dispatch more jobs MapReduce-style.

After the release of PHP five.0 in 2004, 5.1 followed in 2005 with the new DateTime implementation, PDO, and performance enhancements. PHP 5.2 came in 2006 and brought an improved memory manager, JSON support, and input filtering. At that time we started the push to PHP 6, that was a super-ambitious plan to fully rewrite everything round the icu (International components for Unicode) library. It turned out to be a little too ambitious - we could not get enough developers excited concerning it, and instead over up rolling all the varied features that had been sitting around looking ahead to PHP 6 into a PHP 5.3 unleash in 2009. This 3-year gap between 5.2 and 5.3 also meant that five.3 brought plenty of recent things to PHP: namespaces, late static binding, closures, trash collection, restricted goto, mysqlnd (MySQL native driver), far better Windows performance, and lots of alternative things.

In savvy, it probably would have created sense to call this release PHP 6, however PHP 6 had become synonymous with the Unicode effort to the purpose that books had even been written about it, thus we did not feel we might release PHP 6 while not a serious push toward Unicode. we did introduce an icu extension called “intl” that also compiles against PHP 5.2, which gives you access to much of ICU's functionality. The mbstring extension has improved steady over time, which means that pretty much any Unicode-related drawback includes a solution, it simply isn't cleanly integrated into the language itself.

This brings us to the PHP 5.4 release in 2012. Again, an nearly 3-year gap between releases, that is something we wish to enhance upon. i'd like to get back to annual releases with fewer new features in each.

Php 5.4: Memory and performance improvements :

A number of internal structures are created smaller or eliminated entirely, that has resulted in 20-50% memory savings in massive PHP applications. And performance is up by 10-30% (heavily dependent on what your code is doing) through variety of optimizations as well as inlining numerous common code-paths, $GLOBALS has been extra to the JIT, the ‘@’ operator is quicker, run-time class/function/constant caches are extra, run-time string constants ar currently interned, constant access is quicker through pre-computed hashes, empty arrays ar faster and consume less memory, unserialize() and FastCGI request handling is quicker, and more memory and performance tweaks were created throughout the code.

Some early test have shown that zend Framework runs 21st quicker and uses 23rd less memory beneath 5.4, as an example, and Drupal uses 500th less memory and runs about 7-membered quicker.

Instance method call:

Related to function array dereferencing, you can now call a method on object instantiation. And as in previous versions, you can of course still chain method calls, so you can now write code like this:

class foo {
    public $x = 1;

    public function getX() {
        return $this->x;
    }
    public function setX($val) {
        $this->x = $val;
        return $this;
    }
}

$X = (new foo)->setX(20)->getX(); 
echo $X; // 20

Although, unless your constructor is doing something helpful, since the instantiated object is thrown away maybe you should be using a static method call here instead. If we mix it with the short array syntax and function array de-referencing we can write some extremely convoluted code:

class foo extends ArrayObject {
    public function __construct($arr) {
        parent::__construct($arr);
    }
}

echo (new foo( [1, [4, 5], 3] ))[1][0];


No comments:

Post a Comment