Testing Unreleased Features of PHP
We'll be discovering and testing a completely unreleased feature of php-src from an RFC that's still under discussion.
If you've ever wanted to be ahead of the curve of PHP features or you've just wanted to contribute back to PHP internals, testing an unreleased feature from an RFC is a fun and educational way to do so.
RFC TL;DR
Before features can be added to PHP or before any breaking changes can occur, the change must first go through the Request for Comments (RFC) process.
It's pretty rare for an RFC to exist without a link to the implementation which exists as a pull request to the official php-src repo with the "RFC" label.
So how do we pull down one of these implementations to start playing with it while it's still under development? Let's look at one that's under development at the time of writing.
Typed properties 2.0 RFC
Back in 2016, Joe Watkins & Phil Sturgeon created an RFC to add typed properties to PHP 7.1. Unfortunately there were some issues with the implementation that ultimately caused the RFC to be declined in the voting phase.
Fast-forward to June 2018, Bob Weinand & Nikita Popov are reviving Joe & Phil's work and giving typed properties another shot with the typed properties 2.0 RFC.
Typed properties TL;DR
In a nutshell, typed properties allow us to add type declarations directly to class properties. So instead of defining the types with DocBlocs like we do in PHP today...
class Foo
{
/** @var int $id */
public $id;
}
...with typed properties we can declare the types directly on the property before the variable name.
class Foo
{
public int $id;
}
This new feature is much less verbose, easier to read, and enforced by the PHP runtime. All really great things!
Compiling PHP from source
If you haven't already cloned the php-src repo to your machine and compiled it from source, follow the steps outlined in my post on compiling PHP from source.
Git setup
The following steps assume you have a remote called upstream
that points to the original php-src repo. You can check your remotes by running git remote -v
from the command line in the php-src
directory.
$ git remote -v
origin git@github.com:SammyK/php-src.git (fetch)
origin git@github.com:SammyK/php-src.git (push)
upstream git@github.com:php/php-src.git (fetch)
upstream git@github.com:php/php-src.git (push)
If you don't see a reference to upstream, you can add it with the following command.
$ git remote add upstream git@github.com:php/php-src.git
Fetch the RFC implementation from GitHub
You can fetch a pull request (PR) from GitHub into a branch that you define with the following template command.
$ git fetch upstream pull/{pr-id}/head:{some-br
Truncated by Planet PHP, read more at the original (another 10368 bytes)