If you have been following the news in the PHP community as of late, you may have noticed a lot of talk about the next version of the language, PHP 7.

New PHP Install

On March 15th PHP 7 was put under a feature freeze. This means that no voting can start for any new features aimed at the 7.0 release of PHP and instead must be aimed at PHP 7.1. Lets take a look at some of the features that will be coming to a PHP install near you.

The Removal of PHP4 Constructors

This is a fairly simple proposal which could have an impact for those with some older code bases. Back in the days of PHP4 a constructor used to be defined in the same way a language like Java or C++ would handle a constructor.

class MyClass {
    function MyClass()
        // construct the object

However in PHP5, the __construct magic method was introduced. This allowed you to overwrite the parent __construct of a base class and also has the added benefit of being much clearer that this method is called when the object is constructed.

class MyClass {
    function __construct()
        // Construct the object
        // call the parent if you need to

If you have a legacy codebase, this can cause a few troubles when upgrading. Thankfully there are already many tools out there like phpcs which can help you convert your code bases constructors over very quickly.

Return Type Declarations

The multitude of return type RFCs has caused quite a storm in the PHP community over the past few weeks. There are a few groups of people who all want different things out of return type declarations in PHP, and you can’t please them all at once. After some of the RFCs falling through, a community member leaving and much debate, this RFC has finally been accepted.

To sum up the RFC, these return types will allow you to be more explicit about what type of data a function should return. This should allow you to catch errors at runtime during development instead of when it is too late in production.

A simple function might go from this:

function foo() {
    return [];

To this:

function foo() : array {
    return [];

Removing Deprecated Functionality

While this one is sort of covered by the removal of PHP 4 constructors I think it is a good idea to mention that a large amount of functionality that was deprecated in PHP 5 will be removed in PHP 7. This is something to consider if you are intending to upgrade an old PHP code base to PHP 7.

You can read more details on what will be removed here, but the general overview is that the following will be removed:

  • ext/mysql - These are the old style mysql_ functions. Beware if you are working on a codebase that still uses these. This will be the case for most codeigniter projects pre version 3.

  • set_magic_quotes_runtime and magic_quotes_runtime - These have been deprecated for quite a while now so it’s good to seem them finally go.

  • iconv.input_encoding and iconv.output_encoding

  • # style comments in ini files - This is something to watch out for when you upgrade, so make sure you replace all # styles comments with ; before doing anything else

  • preg_replace() eval modifier - For the security conscious out there this one will be a relief if you are to upgrade to PHP 7 

Are you looking forward to the new PHP update? Let us know in the comments below or join the conversation on social media by using #ALJTMedia!

Make your Instagram beautiful. Preview your images before you post them ›