PHP 5.6 End of Beta

Tweet

On June 5th 2014, the PHP group announced the fourth and final beta of the 5.6 version. This milestone ends the beta program and begins the RC program (currently planned for June 19th), which will from now on focus exclusively on making sure the version is stable enough for release. As is customary with a beta program, no new features were added since beta 1 – all the releases were bugfix and improvement patches only.

Changes

Some five months ago we published a list of upcoming new 5.6 features, and since then the PHP group has created a more approachable summary of the changes than one that can be seen in the cryptic changelogs. The list, also called the 5.6 migration guide, is an already very useful work in progress and contains a simple demo of every new feature that matters – you can check it out here.

If you’re interested in seeing all the bugfixes through the betas, you can read the changelog on Github.

Things we haven’t covered in our original post but which have been added in the meanwhile are:

Exponentiation

In a nutshell, “exponentiation via **” it’s an operator which lets you easily calculate a number to the power of another number. However, the order of execution might be counter-intuitive to some. The example states:

$a = 2**3; // $a = 8, i.e. 2^3
$b = 2**3**2; // $b is 512

Most people new to the exponent operator will assume the second line groups operations as such:

(2**3)**2

which would come down to 8**2 which is 64, and not 512. However, the exponential operator here uses the following preference:

2**(3**2)

which comes down to 2**9, and that is 512. Thus, the exponent operator executes from right to left, as is the case in other languages (e.g. Python).

Default UTF-8

The default character encoding has been set to UTF-8 and uses the default_charset ini setting / function.

In an era of super-wide audience reach, having UTF-8 support is of utmost importance. Defaulting to UTF-8 skips several steps developers have had to do with mbstring and iconv previously (now deprecated) in order to support not only reading and writing accurate UTF-8 database data (you still need to configure your database for UTF-8, since it doesn’t have anything to do with PHP) but also to be able to both code on a system with a default local charset, and to display the webpage properly in the browser. With this, there’s no longer any need to set default_charset in the ini settings – it’s set for you as soon as you install PHP.

php://input is reusable

One detail we haven’t mentioned in the last post is the fact that php://input is now reusable – contrary to what the documentation page says. This means you can read it several times now, and it always reads from the same data, which has resulted in a significant memory usage reduction.

GMP operator overloading

GMP, a library we briefly covered before, now supports operator overloading. Previously, you had to use gmp_* functions to, for example, add two GMP objects/resources together (i.e. gmp_add) – now, you can use simpler expressions like +, just like you would with regular numbers.

We are looking for in depth GMP tutorials and real world use cases, so if you’d like to contribute, let us know.

Security upgrades

The function hash_equals() was added, the gost-crypto hash algorithm was introduced, and various SSL/TLS enhancements were implemented.

We won’t be going into detail with these – they’re both outside the scope of this quick overview and complex enough to warrant their own post (care to write it? Let me know), but you can read the details on their respective links.

pgsql async

Pgsql, the extension for PHP’s communication with the PostgreSQL database, now has support for asynchronous operations, joining MySQL in this regard. Asynchronicity might not be exactly what one would assume, so some experimentation is warranted before putting your faith into these operations, but it’s nice to know it’s there nonetheless.

You can see full examples of using PostgreSQL asynchrounously in the tests.

Other changes

These new features aren’t the only thing you should keep in mind – the new docs have several very handy sections helping you transition properly.

BC breaks

The Backwards Incompatible Changes list will tell you about all the areas in which your old apps will fail if used in the same manner they were used up until version 5.6. Some of them are:

  • GMP resources are now objects, which will break previous usages of is_resource
  • mcrypt requires valid keys and IVs
  • json_decode is more strict about upper/lower case on “true”, “false” and “null”
  • and more

Deprecated Features

The deprecated features page lists all the features that will now trigger the E_DEPRECATED error in your code. In this version, they’re calls from incompatible context, $HTTP_RAW_POST_DATA and always_populate_raw_post_data, but one should be mindful of previously deprecated features too – most notably the mysql_* functions of the mysql extension, which is now officially deprecated in its entirety and shouldn’t be used.

Changed Functions

The changed functions list will describe in which way certain functions have changed when compared to their iteration in the previous version. Most notably, they’re the crypt function which now raises a notice if you omit the salt param, the source of mcrypt_create_iv() which now defaults to MCRYPT_DEV_URANDOM, some PostgreSQL functions no longer being experimental, and more.

New Functions

Similar to the new features page, the new functions page lists all the new core and extension functions you can use. For example, the ability to set a password for a Zip archive we’ve mentioned in the last new features post is mentioned on this page.

OpenSSL changes

The OpenSSL changes were so numerous in this release, they warranted their own separate page: http://docs.php.net/manual/en/migration56.openssl.php

This page contains everything from certificate and fingerprint change instructions and explanations to SPKI and more. If you’re a security buff, you’re encouraged to give this a thorough read, and after you do, you’re encouraged to write an in-depth explanation for us :) Let us know if you can make this knowledge reach more eyes in a style appropriate for a wider audience.

Other Changes and Global Constants

The last two pages present other changes in extensions that didn’t fit any other category, and an exhaustive list of new global constants available – albeit without any detailed explanation.

Conclusion

If you’re moving from any other previous version of PHP to a newer one, please pay attention to the migration guides available for all such jumps: http://docs.php.net/manual/en/appendices.php

These guides will cover all major and minor version differences you should know about, and will help you prepare your environment for a potential switch to the latest and greatest.

The end of beta for 5.6. marks a new, important milestone in the PHP community. Several important new features await us as we transition to this new version, and the core developers encourage everyone to test this version and report feedback on any problems they might encounter. The following couple of months will be dealing with Release Candidate versions exclusively, and with the very next version (scheduled for June 19th), it’s safe to say you can start testing 5.6. in production. In the meanwhile, download the beta and start testing!

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

  • http://aasiutin.com/ Aleksey Asiutin

    >so if you’d like to contribute, let us know.
    How often do you guys check editor@sitepoint.com email address? I wrote you about precision math article topic couple of days ago.

    • http://www.bitfalls.com/ Bruno Skvorc

      Sorry about that! You’d best get in touch with me directly via bruno.skvorc@sitepoint.com, Twitter or G+, the editor address isn’t in my direct jurisdiction

      • http://aasiutin.com/ Aleksey Asiutin

        Okay, thanks!

  • http://evanbyrne.com Evan Byrne

    Good to see that they have finally made UTF-8 the default! Having to deal with that character encoding mess was one of the big reasons I gave up on PHP.

  • http://r.je Tom Butler

    Strange that you went into detail about the exponential operator but didn’t mention the variadic functions and argument unpacking which are probably going to be much more useful to most people!

  • Dave Tasker

    64 bit production versions for Windows would be nice