PHP 7.1: a few other things

September 14, 2016php, php-7.1, english
 This has been written a few years ago and might not be up-to-date…

Cet article est aussi disponible en français.
This is the 8th post in a series about PHP 7.1.

After a year of work, evolutions brought by PHP 7.1 are not limited to those I presented these past few days!

Here's the rest of the list, grouping in this post pretty-much all remaining new features, even if they didn't really catch my eye for now -- but might still be of interest to some of you?

Asynchronous Signal Handling

Until PHP 7.1, dealing with signals with the pcntl extension required us to call pcntl_signal_dispatch() by hand, synchronously, or to use declare(ticks=1) -- with a non-negligible impact on execution.

We use PHP more and more in command line or for long scripts, in which cases we must often deal with signals efficiently, as they are a rather typical inter-process communication mean. To answer this need, we can now, with PHP 7.1, handle signals asynchronously, thanks to the new pcntl_async_signals() function.


pcntl_signal(SIGTERM, function ($signo) {
    var_dump("SIGTERM"); die;

while (true) {

Sending a TERM signal to our process (via kill 31321 and adapting the PID ;-)) will cause the execution of the callback function, which in this example displays the name of the signal and ends the script.

The pcntl.async_signals configuration directive, which defaults to 0, allows us to systematically enable this behavior, without having to call pcntl_async_signals(true). This default value will probably change in a future version of PHP.

‣ The: Asynchronous Signal Handling

Octal overflow detection

With PHP, we can include a byte in a string, using its octal representation:

$str = "Un caractère : \123";
// string(17) "Un caractère : S"

But, for this representation to really fit in one byte, its firts digit must be between 0 and 3. A higher digit will cause an overflow: "\400" will actually correspond to "\000", "\500" will be interpredted as "\100" and so on. This means the following piece of code results in the same output as the previous one:

$str = "Une tentative : \523";
// string(17) "Une tentative : S"

This overflow was silent with PHP 7.0. Now, with PHP 7.1, the behavior remains the same but a warning will be raised, indicating the developer she wrote something odd:

Warning: Octal escape sequence overflow \523 is greater than \377 in .../demo-01.php on line 12

‣ The RFC: Octal overflow detection

And some other stuff, if you are curious

Finally, and presented as-is, here are the other RFCs which passed and will bring new features for PHP 7.1 -- I won't be giving any example nor present them more in detail:

These evolutions shouldn't have much impact on your application, but could still be helpful in some situations -- like allowing for a more precise representation of floatting-point values or beginning introducing support for HTTP/2.

The end of this series is getting near, but I still have a few points I want to write about.
Tomorrow, we'll see a list of ideas which have been mentionned during the development cycle of PHP 7.1 but ended up not being adopted.

You liked this post? Spread the word!

This blog has recently been migrated to a static site generator and I haven't had time to setup a commenting solution yet.

With a bit of luck, I'll manage to take care of this in a few weeks ;-)