PHP 5.6 Innovative features web developers would love to embrace

Filed Under: PHP

Ever since it came into existence, PHP has been serving web developers incredibly effective features and functions that have helped them in delivering high-end websites and web applications. After gathering immense appreciation for its 5.4 version, PHP has now come up with the 5.6 version that’s equipped with unexpectedly rich features that are surely going to help web developers take a sigh of relief. Through this post, I intend to throw some light on the lesser-known features of PHP 5.6 which look promising when it comes to building out-of-the-box web portals and apps.

Moderations made to File Uploads

Before the release of the PHP version 5.6, it wasn’t possible for the developers to upload stuff that occupied over 2GB memory space. Poor handling and processing were the two basic reasons behind this incompetency of PHP 5.6. Now, the PHP development team has outlines that the software now fully supports the file uploads of arbitrary size. Also, PHP 5.6’s data memory usage has been reduced by 2-3 times as compared to that of PHP 5.4. Such modifications to the file upload system has enables developers to re-open and re-use the input in accordance to their varying requirements.

Flexibility to import Namespace Constants and Functions

Unlike the previous versions of PHP, the version 5.6 enables you to import the namespaced constants and functions directly into a suite of classes. Here’s the code snippet that’s used for importing the namespace constants and functions:


namespace NamespaceTest {

const SCORE = 1;

function getScore() {

# ...

}

}

namespace {

use NamespaceTest as Test;

var_dump(TestgetScore());

}

If you’re keen on importing the standalone segments of code, then you can do the same in PHP 5.6 with the help of use function and use const statements as explained below:


namespace {

use function NamespaceTestgetScore;

use const NamespaceTestSCORE;

getScore();

}

Better support for Variadic functions

PHP Version 5.6 comes with full-fledged support for variadic functions. This makes it simpler for the developers to deal with variable argument lists available for methods and functions. Variadic functions play a vital role in improving readability and reducing the code complexity that’s prevalent during the process of handling variable argument lists. And that’s not all, PHP 5.6 also comes with some amazing improvements for the syntac used for these variadic functions. In other words, with PHP 5.6, even after supplying some arguments to the variadic functions, you don’t need to do any splicing after calling the function: func_get_args.

The syntax used for variadic functions in PHP 5.5 was as mentioned below:


class MySQL implements DB {

protected $pdo;

public function query($query) {

$stmt = $this->pdo->prepare($query);

$stmt->execute(array_slice(func_get_args(), 1));

return $stmt;

}

// ...

}

$userData = $db->query('SELECT * FROM users WHERE id = ?', $userID)->fetch();

In contrast to above, the syntax used for variadic functions in PHP 5.6 is as explained below:


class MySQL implements DB {

public function query($query, ...$params) {

$stmt = $this->pdo->prepare($query);

$stmt->execute($params);

return $stmt;

}

// ...

}

Support for Internal Operator Overloading

This is a feature, which I’m sure most of the PHP developers might not be aware of. PHP 5.6 comes with support for operator operating in internal classes, making the development process simpler and the code easier-to-read. Well, there are several reasons that made overloaded operators a better choice than the gmp_add($a, $b) style functions. Two of the most crucial ones are mentioned below:

  • Code that uses the overloaded operators is simpler to read.
  • Overloaded operators allow polymorphism for the functions that perform a variety of arithmetic operations.

A considerable reduction in the POST data memory usage

As compared to the PHP 5.4, the version 5.6 comes with a POST data memory usage that’s been reduced by over 2-3 times. This has been made possible with the removal of two things:

  • The always_populate_raw_post_data setting from the php.ini file
  • The superglobal variable $HTTP_RAW_POST_DATA

With the new PHP 5.6 release, you no longer need to access raw post data, rather you need to rely on a solution as mentioned below:


$postdata = file_get_contents("php://input");

An improved ZIP library

PHP 5.6 comes with an improved Zip library in the form of new methods. ZipArchive: : setPassword($password) is the methods that allows you to create password protected Zip files in a flexible way.

Summary

PHP 5.6 definitely looks befitting for developers who are into the habit of exploring PHP and its components for building fine-quality apps and websites. Do share your feedback/comments on my write-up using the comments box below.

Author Bio: Maria Mincey is a prolific writer, who brings to the table a quantum of knowledge around PHP Development Services and combines it with her creative writing skills. She works for Xicom Technologies Software Development Company.

Comments

  1. khalid nasir khan says:

    sir :
    what is the future of php and what is the growth in this programming language…?

Leave a Reply

Your email address will not be published. Required fields are marked *

close
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages