Object properties and immutability – larry@garfieldtech.com

Object properties and immutability

There has been much discussion in recent weeks in PHP circles about how to make objects more immutable. There have been a number of proposals made either formally or informally that relate to object property access, all aimed at making objects safer through restricting write access in some way.

Since my last mega post on PHP object ergonomics was so well-received and successful (it resulted in both constructor promotion and named arguments being added to PHP 8.0, thanks Nikita!), I figure I’ll offer another summary of the problem space in the hopes of a deeper analysis suggesting a unified way forward.

Continue reading on PeakD

Larry
28 December 2020 – 5:30pm

Xdebug Update: November 2020 – Derick Rethans

Xdebug Update: November 2020

Another monthly update where I explain what happened with Xdebug development in this past month. These will be published on the first Tuesday after the 5th of each month.

Patreon and GitHub supporters will get it earlier, on the first of each month.

I am currently looking for more funding, especially now some companies have dropped out, and that GitHub sponsors is no longer matching supporters.

You can become a patron or support me through GitHub Sponsors. I am currently 73% towards my $1,000 per month goal.

If you are leading a team or company, then it is also possible to support Xdebug through a subscription.

In November, I worked on Xdebug for about 72 hours, with funding being around 30 hours. I worked mostly on the following things:

Xdebug 3

The biggest thing this month is the release of Xdebug 3!

After about a year and a half after starting with this massive undertaking, it is finally ready. I released it the day before PHP 8 came out. Of course Xdebug 3 also supports PHP 8. It however drops support for PHP 7.1 as per the support policy.

As is custom with a x.0.0 release, a few bugs did occur. I am currently working at addressing then. I plan to release bug release versions weekly throughout December, as long as it makes sense to do so.

Xdebug 3 should be a lot faster, as it is a lot more clever on when it hooks into things it needs to do. That does come with changes as to how Xdebug needs to be configured. Xdebug 3’s upgrade guide lists all the changes.

The https://xdebug.org web site now only contains Xdebug 3 documentation, with the old site archived at https://2.xdebug.org until the end of 2021.

I will be recording some videos about the ideas behind the changes, and how to use Xdebug 3. I am also playing with the idea of hosting “Office Hours” for an hour a week where users can drop-in with questions and problems. If that is something that you’re interested in, please let me know.

Xdebug Cloud

I have been continuing to test Xdebug Cloud, and I am working with a few private alpha testers. They’re putting the hosted Cloud service to its paces with the latest PhpStorm 2020.3 release candidate. As I suspected, the alpha testers found some minor issues which I will be addressing during December.

The web site for Xdebug Cloud does not have a design yet, but this is coming this month as well.

If you want to be kept up to date with Xdebug Cloud, please sign up to the mailinglist, which I will use to send out an update not more than once a month.

Business Supporter Scheme and Funding

In November, two new supporters signed up.

Thank you Find My Electric and Edmonds Commerce!

If you, or your company, would also like to support Xdebug, head over to the support page!

Besides business support, I also maintain a Patreon page and a profile on GitHub sponsors.

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!