I was waiting for PHP 7.4 to be released. The most exciting feature for me is Typed Properties. Being released today, I was eager to compile it just to see that feature in action (and I’m also curious about Opcache Preloading).
I compiled it inside a Docker container and wrote a small test file.
Dockerfile:
FROM ubuntu:18.04 ARG VERSION=7.4.0 RUN apt update RUN apt install -y wget gcc make automake pkgconf libxml2-dev libsqlite3-dev RUN wget https://www.php.net/distributions/php-$VERSION.tar.gz RUN tar xzfv php-$VERSION.tar.gz WORKDIR php-$VERSION RUN ./configure \ --with-pdo-mysql \ --with-mysqli RUN make -j $(nproc) #RUN make test # probably fails for now RUN make install RUN php -v
Compile PHP:
docker build . -t php740build
Save this as test.php:
<?php declare(strict_types=1); class Calc { /** * @var float[] */ private array $nums; /** * Calc constructor. * @param float $n * @param float[] $nums */ public function __construct(float $n, float ...$nums) { $this->nums = [$n, ...$nums]; } /** * @return float */ public function sum(): float { return array_sum($this->nums); } } $calc = new Calc(1, 2, 3); echo $calc->sum(); echo "\n";
Run the test:
docker run --rm -v $PWD/test.php:/test.php -ti php740build php /test.php
It’s probably better to wait a while for some patches after being tested in the wild wild web.