• Overview
    Key features
    • Observability
    • Auto-scaling
    • Multiframework
    • Security
    Frameworks
    • Django
    • Next.js
    • Drupal
    • WordPress
    • Symfony
    • Magento
    • See all frameworks
    Languages
    • PHP
    • Python
    • Node.js
    • Ruby
    • Java
    • Go
  • Industries
    • Consumer Goods
    • Media/Entertainment
    • Higher Education
    • Government
    • Ecommerce
  • Pricing
  • Featured articles
    • Switching to Platform.sh can help IT/DevOps organizations drive 219% ROI
    • Organizations, the ultimate way to manage your users and projects
  • Support
  • Docs
  • Login
  • Request a demo
  • Free Trial
Meet Upsun. The new, self-service, fully managed PaaS, powered by Platform.sh.Try it now
Blog
Illustration of an elephant with heart-shaped glasses

Pre-release PHP 8.0 images now available

php
03 September, 2020
Larry Garfield
Larry Garfield
Director of Developer Experience

Like clockwork, the next release of PHP is slated to come out on November 26th. It's packed with new features and performance improvements, as well as general overall polish. And as usual, you can try it out early on Platform.sh with a single-line change.

We now have a php:8.0-rc container image available. That is rc meaning our prerelease, not PHP's RC phase. It is PHP 8.0 beta 3 (just released as of this writing), but we will be updating it periodically as new pre-release versions of PHP 8 are released in the coming weeks.

How to use the new PHP 8 container on Platform.sh

To use the new container image, edit your .platform.app.yaml file and change the type line to php:8.0-rc. That's it.

# .platform.app.yaml
name: app

type: "php:8.0-rc"

Commit and push, and now you'll be running PHP 8.0.

There are a few caveats, of course:

  • This is a pre-release image and therefore not recommended for production. Test it on a branch to see if your code is ready, and report bugs if you find them, but we won't be providing support for it until the final image is released in late November.
  • Many common PHP extensions are not yet available for PHP 8, so are not included. We will add them over time as they become available, but be aware that not all extensions work yet.

Otherwise, it's ready for playing around, testing, and making sure your codebase is ready for 8.0.

Why use PHP 8?

Not every PHP release has a long list of new features, but PHP 8.0 definitely does. A complete changelog is still in progress (it is pre-release, after all), but among the most exciting features are union types, named parameters, and attributes.

Union types means you can now specify a type declaration to be one of multiple options. For example, the following function will accept either a string or an integer and will return either an integer or a float:

<?php
function example(string|int $input): int|float
{
    // some code here
}

Named parameters are a feature found in a number of languages and are now available to PHP. Can't remember if it's ($needle, $haystack) or ($haystack, $needle)? ¿Porque no los dos?

<?php
if (in_array(haystack=$arr, needle=$find)) {
    // ...
}

Named parameters are supported for all functions and methods automatically; there's no additional work needed on the function declaration.

Finally, attributes are likely to be PHP 8.0's signature feature. If you've worked with Doctrine Annotations before, they're basically that but baked into the language using the reflection system. The syntax had some last-minute changes, though, so the current release doesn't have the final syntax. The final syntax will be included in RC1 and is borrowed from Rust:

<?php
#[Route(name='foo', path='/foo/bar')]
function my_route(int $id): ResponseInterface
{
    // ...
}

The Route annotation here will have no impact at runtime. However, it will be available to reflection, making it possible to easily load a Route object called with that constructor. (Note the use of named parameters.) Unlike the existing convention of using docblocks, native annotations support the full language syntax, can be linted, and require no additional libraries to work. Attributes can be placed on functions, classes, interfaces, methods, properties, and even function/method parameters.

And of course there are numerous changes to tighten up the language, make error handling more robust, and catch more errors earlier. 99% of the time those tweaks have no impact, but they do sometimes cause small backward compatibility breaks for a few code bases. If you're concerned that yours is one of them, give PHP 8.0 a pre-release whirl on Platform.sh! If you find bugs, be sure to report them to the PHP team so they can be fixed before the final release.

Get the latest Platform.sh news and resources
Subscribe

Related Content

Running with FrankenPHP on Platform.sh

Running with FrankenPHP on Platform.sh

Company
AboutSecurity and complianceTrust CenterCareersPressContact us
Thank you for subscribing!
  •  
Field required
Leader Winter 2023
System StatusPrivacyTerms of ServiceImpressumWCAG ComplianceAcceptable Use PolicyManage your cookie preferencesReport a security issue
© 2024 Platform.sh. All rights reserved.
Supported by Horizon 2020's SME Instrument - European Commission 🇪🇺