Development-Mode Modules for Mezzio – Matthew Weier O’Phinney

I fielded a question in the Laminas Slack yesterday that I realized should likely be a blog post.
The question was:

Is there a way to register development-mode-only modules in Mezzio?

There’s actually multiple ways to do it, though one that is probably more preferable to others.

Conditional ConfigProviders

We already provide one pattern for doing this in the Mezzio skeleton application, by conditionally including the mezzio-swoole ConfigProvider if the class is present:

class_exists(\Some\ConfigProvider::class) ? \Some\ConfigProvider::class : function (): array { return []; },

Alternately, you could express this as an anonymous function:

function (): array { if (class_exists(\Some\ConfigProvider::class)) { return (new \Some\ConfigProvider())(); } return [];
},

(The values provided to the ConfigAggregator constructor can be either string class names of config providers, or functions returning arrays, which is why either of these will work.)

This approach is primarily useful if the config provider will only be installed as a require-dev dependency.
But what if you are defining the config provider in your own code, and it’s always present?

Development-Mode Configuration Aggregation

Another possibility is to do some “hacking” around how laminas-development-mode works with Mezzio.
laminas-development-mode in Mezzio works with the config/autoload/development.local.php.dist file; enabling development mode symlinks config/autoload/development.local.php to that file.
That file just needs to return an array.
As such, you could totally write it to aggregate other config providers, as well as some default development configuration, using the same tools you do in your primary configuration file:

// in config/autoload/development.local.php.dist: declare(strict_types=1); use Laminas\ConfigAggregator\ArrayProvider;
use Laminas\ConfigAggregator\ConfigAggregator; $developmentConfig = [ // app-level development config you want to define
]; $aggregator = new ConfigAggregator([ // any ConfigProviders you want to list, then: new ArrayProvider($developmentConfig),
]); return $aggregator->getMergedConfig();

This approach is likely the best to use, as it makes it more clear in your main config what the default modules are, and any dev-only ones are now listed in this file.

mwop Development-Mode Modules for Mezzio was originally published on https://mwop.net by .

Install PHP 8.0 on CentOS, RHEL or Fedora – Remi Collet

Here is a quick howto upgrade default PHP version provided on Fedora, RHEL or CentOS with latest version 8.0.

You can also follow the Wizard instructions.

 

Repositories configuration:

On Fedora, standards repositories are enough, on Enterprise Linux (RHEL, CentOS) the Extra Packages for Enterprise Linux (EPEL) repository must be configured, and on RHEL the optional channel must be enabled.

Fedora 33

dnf install https://rpms.remirepo.net/fedora/remi-release-33.rpm

Fedora 32

dnf install https://rpms.remirepo.net/fedora/remi-release-32.rpm

RHEL version 8.3

dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

RHEL version 7.9

wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
wget https://rpms.remirepo.net/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm
subscription-manager repos --enable=rhel-7-server-optional-rpms

CentOS version 8

dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

CentOS version 7

wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
wget https://rpms.remirepo.net/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm

 

php module usage

With Fedora modular and RHEL / CentOS 8, you can simply use the remi-8.0 stream of the php module

dnf module reset php
dnf module install php:remi-8.0

 

remi-php80 repository activation

Needed packages are in the remi-safe (enabled by default) and remi-php80 repositories, the latest is not enabled by default (administrator choice according to the desired PHP version).

RHEL or CentOS 7

yum install yum-utils
yum-config-manager --enable remi-php80

Fedora

dnf config-manager --set-enabled remi-php80

 

PHP upgrade

By choice, the packages have the same name than in the distribution, so a simple update is enough:

yum update

That’s all 🙂

$ php -v
PHP 8.0.0 (cli) (built: Nov 24 2020 17:04:03) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies with Zend OPcache v8.0.0, Copyright (c), by Zend Technologies

 

Known issues

The upgrade can fail (by design) when some installed extensions are not yet compatible with  PHP 8.0.

See the compatibility tracking list: PECL extensions RPM status

If these extensions are not mandatory, you can remove them before the upgrade, else, you will have to be patient.

Warning: some extensions are still under development, but it seems useful to provide them to allow upgrade to more people, and to allow user to give feedback to the authors.

 

More d’information

If you prefer to install PHP 8.0 beside the default PHP version, this can be achieved using the php80 prefixed packages, see the PHP 8.0 as Software Collection post.

You can also try the configuration wizard.

The packages available in the repository will be used as sources for Fedora 35 (if self contained change proposal is accepted).

By providing a full feature PHP stack, with about 130 available extensions, 7 PHP versions, as base and SCL packages, for Fedora and Enterprise Linux, and with 300 000 download per day, remi repository became in the last 15 years a reference for PHP users on RPM based distributions, maintained by an active contributor to the projects (Fedora, PHP,

Truncated by Planet PHP, read more at the original (another 888 bytes)

PHP Internals News: Episode 72: PHP 8.0 Celebrations! – Derick Rethans

PHP Internals News: Episode 72: PHP 8.0 Celebrations!

In this episode of “PHP Internals News” we’re looking back at all the RFCs that we discussed on this podcast for PHP 8.0. In their own words, the RFC authors explain what these features are, with your host interjecting his own comments on the state of affairs.

The RSS feed for this podcast is https://derickrethans.nl/feed-phpinternalsnews.xml, you can download this episode’s MP3 file, and it’s available on Spotify and iTunes. There is a dedicated website: https://phpinternals.news

Transcript

Derick Rethans 0:23

Hi, I’m Derick, and this is PHP internals news, a weekly podcast dedicated to demystifying the development of the PHP language.

Derick Rethans 0:32

This is Episode 72. PHP eight is going to be released today, November 26. In this episode, we look back across the season to find out which new features are in PHP eight dot zero. If I have spoken with the instigator of each of these features, I’m letting them explain what this new feature is. in the first episode of this current year, I spoke with Nikita Popov about weak maps, a feature that builds on top of the weak references that were introduced in PHP seven four. I asked: What’s wrong with the weak references and why do we now need to weak maps.

Nikita Popov 1:10

There’s nothing wrong with references. This is a reminder, what weak references are about, they allow you to reference, an object, without preventing it from being garbage collected. So if the object is unset, then you’re just left with a dangling reference, and if you try to access it you will get acknowledged sort of the object. Now the probably most common use case for any kind of weak data structure is a map or an associative array, where you have objects and want to associate some kind of data with some typical use cases are caches or other memoize data structures. And the reason why it’s important for this to be weak, is that you do not. Well, if you want to cache some data with the object and then nobody else is using that object, you don’t really want to keep around that cache data, because no one is ever going to use it again, and it’s just going to take up memory usage. And this is what the weak map does. So you use objects as keys, use some kind of data as the value. And if the object is no longer used outside this map, then is also removed from the map as well.

Derick Rethans 2:29

A main use case for weak maps will likely be ORMs and related tools. In the next, episode 38, I discussed this trainable interface with Nicolas Grekas from Symfony fame. I asked: Nicolas, could you explain what stringable is.

Nicolas Grekas 2:45

Hello, and stringable is an interface that people could use to declare that they implement some the magic to string method.

Derick Rethans 2:53

That was a short and sweet answer, but a reason for wanting to introduce this new interface was much more complicated, and are also potential issues with breaking backwards compatibility. Nikolas replied to my questioning about that with:

Nicolas Grekas 3:06

That’s another goal of the RFC; the way I’ve designed it is that I think the actual current code should be able to express the type right now using annotations, of course. So, what I mean is that the interface, the proposal, the stringable is very easily polyfilled, so we just create this interface in the global namespace that declare the method and done, so we can do that now, we can improve the typing’s now. And then in the future, we’ll be able to turn that into an actual union type.

Derick Rethans 3:39

I had a chat with Nikita Popov about union types as part of the last season in Episode 33 before PHP seven four was

Truncated by Planet PHP, read more at the original (another 30852 bytes)

PHP 8.0 brings it all together on Platform.sh – platform.sh

A year in the making, PHP 8.0 has been released to the world! Sporting a plethora of new functionality to offer more power with less code, it’s the most anticipated release of PHP since … well since PHP 7.4 last year. (PHP is exciting, what can I say?) And you can run it today on Platform.sh.
Stronger together As we’ve been covering throughout our series, PHP 8.0 is chock full of new functionality.

Installing PHP extensions without pecl in PHP 8 Docker images – Rob Allen

UPDATE: Since this was published, PR 1087 has been raised and merged with restores pecl to the Docker PHP 8 images.

I discovered recently that pecl is no longer shipped in the PHP Docker images for PHP 8. This appears to be related to the deprecation of --with-pear in PHP core as noted in issue 1029.

Consider this Dockerfile:

FROM php:8.0.0RC5-cli-buster RUN pecl install mongodb && docker-php-ext-enable mongodb

If you build, you’ll discover the pecl cannot be found:

$ docker build -t project1 .
Sending build context to Docker daemon 2.56kB
Step 1/2 : FROM php:8.0.0RC5-cli-buster ---> 8b1f24a39f30
Step 2/2 : RUN pecl install mongodb && docker-php-ext-enable mongodb ---> Running in c013519c47f9
/bin/sh: 1: pecl: not found
The command '/bin/sh -c pecl install mongodb && docker-php-ext-enable mongodb' returned a non-zero code: 127

Fortunately, we can get the source from pecl.php.net ourselves and install it:

FROM php:8.0.0RC5-cli-buster RUN mkdir -p /usr/src/php/ext/mongodb \ && curl -fsSL https://pecl.php.net/get/mongodb | tar xvz -C "/usr/src/php/ext/mongodb" --strip 1 \ && docker-php-ext-install mongodb

As of this writing, it will install version 1.9.0RC1 which is required for PHP 8 anyway, but you can specify the version by adding it to the URL like this: https://pecl.php.net/get/mongodb-1.9.0RC1

docker build now works.

Job done!

PHP Internals News: Episode 71: What didn’t make it into PHP 8.0? – Derick Rethans

PHP Internals News: Episode 71: What didn’t make it into PHP 8.0?

In this episode of “PHP Internals News” we’re looking back at all the RFCs that we discussed on this podcast for PHP 7.4, but did not end up making the cut. In their own words, the RFC authors explain what these features are, with your host interjecting his own comments on the state of affairs.

The RSS feed for this podcast is https://derickrethans.nl/feed-phpinternalsnews.xml, you can download this episode’s MP3 file, and it’s available on Spotify and iTunes. There is a dedicated website: https://phpinternals.news

Transcript

Derick Rethans 0:15

Hi, I’m Derick, and this is PHP internals news, a weekly podcast dedicated to demystifying the development of the PHP language. This is Episode 71. At the end of last year, I collected snippets from episodes about all the features that did not make it into PHP seven dot four, and I’m doing the same this time around. So welcome to this year’s ‘Which things were proposed to be included into PHP 8.0, but didn’t make it. In Episode 41, I spoke with Stephen Wade about his two array RFC, a feature you wanted to add to PHP to scratch an itch. In his own words:

Steven Wade 0:52

This is a feature that I’ve, I’ve kind of wish I would have been in the language for years, and talking with a few people who encouraged. It’s kind of like the rule of starting a user group right, if there’s not one and you have the desire, then you’re the person to do it. A few people encouraged to say well why don’t you go out and write it? So I’ve spent the last two years kind of trying to work up the courage or research it enough or make sure I write the RFC the proper way. And then also actually have the time to commit to writing it, and following up with any of the discussions as well.

Steven Wade 1:20

I want to introduce a new magic method the as he said the name of the RFC is the double underscore to array. And so the idea is that you can cast an object, if your class implements this method, just like it would toString; if you cast it manually, to array then that method will be called if it’s implemented, or as, as I said in the RFC, array functions will can can automatically cast that if you’re not using strict types.

Derick Rethans 1:44

I questioned him on potential negative feedback about the RFC, because it suggested to add a new metric method. He answered:

Steven Wade 1:53

Beauty of PHP is in its simplicity. And so, adding more and more interfaces, kind of expands class declarations enforcement’s, and in my opinion can lead to a lot of clutter. So I think PHP is already very magical, and the precedent has been set to add more magic to it with seven four with the introduction of serialize and unserialize magic methods. And so for me it’s just kind of a, it’s a tool. I don’t think that it’s necessarily a bad thing or a good thing it’s just another option for the developer to use

Derick Rethans 2:21

The RFC was not voted on and a feature henceforth did not make it into PHP eight zero.

Derick Rethans 2:27

Operator overloading is a topic that has come up several times over the last 20 years that PHP has been around as even an extension that implements is in the PECL repository. Jan Bøhmer proposed to include user space based operator overloading for PHP eight dot zero. I asked him about a specific use cases:

Jan Böhmer 2:46

Higher mathematical objects like complex numbers vectors, something like tensors, maybe something like the string component of Symfony, you can simply concatenate this string object with a normal string using the concat operator and doesn’t have to use a function to cause this. Most basically this

Truncated by Planet PHP, read more at the original (another 14876 bytes)

PHP 8.0.0 Release Candidate 5 available for testing – PHP: Hypertext Preprocessor

The PHP team is pleased to announce the eleventh testing release of PHP 8.0.0, Release Candidate 5. This is an extra unplanned release, but we’re not planning to adjust the GA date, however, this may change during the course of the RC cycle. The updated release schedule can, as always, be found on the PHP Wiki page about the PHP 8.0. For source downloads of PHP 8.0.0 Release Candidate 5 please visit the download page.Please carefully test this version and report any issues found in the bug reporting system.Please DO NOT use this version in production, it is an early test version. For more information on the new features and other changes, you can read the NEWS file, or the UPGRADING file for a complete list of upgrading notes. These files can also be found in the release archive. The next release will be the General Availability, planned for Nov 26 2020.The signatures for the release can be found in the manifest or on the QA site.Thank you for helping us make PHP better.

PHP 8.0 feature focus: Named Arguments – platform.sh

Last week’s installment talked about the most contentious new feature of PHP 8.0. In our 10th and final installment, we’ll cover the formerly most contentious feature, one that somehow managed not only to generate little pushback this time around, but to become one of PHP 8.0’s top new features.
In every programming language that has functions (that is, all of them), functions can be called by passing an ordered list of arguments to them as input parameters.

Platform.sh | Journeys Erin Austin + Céline Villet Boongo – platform.sh

Speaking the language of family: how two Platform.sh veterans forged a friendship across the Atlantic Ocean One’s daily commute takes her to the Strasbourg – Saint-Denis stop of the Paris Métro, from where she steps out onto the Boulevard St. Denis, walks a half-block to the Boulevard de Sébastopol, and turns left, passing the sidewalk tables of a trendy brasserie before marching through the elaborately carved stone archway of her office building.