This article is a recap of participating in the Online PHP Conference organised by the folks of thePHP.cc held in January 2021.

The COVID-19 pandemic is still raging and all in-person events are still on hold since March 2020. Over the past months, events have shifted towards online platforms to continue sharing knowledge, ideas and to build communities.

Our friends at thePHP.cc organized “The Online PHP Conference” last week to do just that. And I will share my takeaways from this event as I consider them valuable learnings to become a better professional.

Fully Typed PHP

Sebastian Bergmann giving us a trip down memory lane (source: Twitter)

The first day of the event started with a session given by Sebastian Bergmann on Fully Typed PHP. Even the conference was streaming live, Sebastian played a pre-recorded session but paid great attention to wear the same shirt as he did during the recordings, which was a very nice touch.

The key lesson I got from this session was the benefit of using PHP 8’s named parameter types and how well it was integrated in JetBrains’ PHPStorm IDE.

In the following class method I’ve created logic to return a string with a player’s name, their score and optional message.

<?php declare(strict_types=1);

namespace In2it;

class NamedTypes
{
    public function getPlayerScore(
        string $name,
        int $score = 0,
        string $reason = ''
    ): string
    {
        if ('' !== $reason) {
            return sprintf(
                'Player %s has a score of %d because they %s',
                $name,
                $score,
                $reason
            ) . PHP_EOL;
        }
        return sprintf(
            'Player %s has a score of %d',
            $name,
            $score
        ) . PHP_EOL;
    }
}

In normal circumstances I would need to provide all arguments if I wanted to provide the optional message, even though the score has a default of 0.

$demo = new NamedTypes();
echo $demo->getPlayerScore('Foo', 10);
echo $demo->getPlayerScore('Bar');
echo $demo->getPlayerScore('Baz', 0, 'got sick while playing');

But with named arguments I can now directly enter the correct values for the arguments I want to use.

echo $demo->getPlayerScore(name: 'FooBar', reason: 'cheated!');

Running this code gives me the expected outcomes.

Player Foo has a score of 10
Player Bar has a score of 0
Player Baz has a score of 0 because they got sick while playing
Player FooBar has a score of 0 because they cheated!

And this is going to be real benefit for those situations where you have a class or method with optional arguments and you only need to change or modify one or two of them.

Patterns for Event-Driven Systems

Stefan Priebsch presenting his session on event system patterns

Stefan Priebsch was presenting a session on patterns for event-driven systems, but because there were technical difficulties I missed a portion of this interesting session, I hope to catch up when the recordings are made available.

But between the technical challenges I was able to pick up on some interesting concepts involving event based architectures and how to solve common challenges while keeping the event system loosly coupled. As we’re entering an era with services that rely on events, the challenges are becoming real. And the design patterns provided by Stefan will be certainly valuable solutions for these common challenges.

Test-Driven Development Live

Sebastian preparing his setup for the TDD session (source: Twitter)

As a TDD practitioner myself it’s always good to see how others do it, compare notes and improve. Luckily for me there was a live streaming session with Stefan Priebsch and Sebastian Bergmann.

It was good for me to see that they confirmed my way of doing TDD was correct. The main difference between them and me is the start of a project. Where I create empty methods with placeholders, they already start with a rudimentary test. I did this too, but I ended up forgetting edge cases.

Here’s how I would approach starting TDD for the NamedTypes class I described earlier.

<?php declare(strict_types=1);

namespace In2it;

use PHPUnit\Framework\TestCase;

require_once __DIR__ . '/phpunit.phar';

class NamedTypesTest extends TestCase
{
    public function testErrorIsThrownIfWhenNoNameArgumentIsProvided(): void
    {
        $this->markTestIncomplete('Write out test');
    }

    public function testOnlyNameAndScoreAreShown(): void
    {
        $this->markTestIncomplete('Write out test');
    }

    public function testNameAndScoreAreShownWithReasonMessage(): void
    {
        $this->markTestIncomplete('Write out test');
    }

    public function testAllIsShownWhenUsingNamedArguments(): void
    {
        $this->markTestIncomplete('Write out test');
    }
}

In my TestDox report I now have a fair understanding what I need to test for and I can invite others to look at it to see if I’m not forgetting anything.

PHPUnit 9.5.1 by Sebastian Bergmann and contributors.

Named Types (In2it\NamedTypes)
 ∅ Error is thrown if when no name argument is provided
 ∅ Only name and score are shown
 ∅ Name and score are shown with reason message
 ∅ All is shown when using named arguments

Time: 00:00.003, Memory: 18.00 MB

OK, but incomplete, skipped, or risky tests!
Tests: 4, Assertions: 0, Incomplete: 4.

Again, this is how I start my TDD journeys and works for me. If you have a different approach let me know in the comments or DM me on social media.

Business Open Source contributions

Stefan Koopmanschap presenting Business Open Source Contributions

This was a very interesting session provided by Stefan Koopmanschap about how his company Ingewikkeld balances work and contributing to open source projects. Especially because In2it is grown thanks to the contributions we have done with and for the PHP community. This session allowed me to compare notes on things that work, things that don’t work and how all of us combined can make open source more sustainable. Stefan, job well done 👍

PHP 8 and Legacy Code

Juliette presenting on PHP 8 and legacy code (source: Twitter)

This was a session given by Juliette Reinders-Folmer about the benefits of migrating to PHP 8 and reasons why it is good to stick with older versions of PHP. With her background in maintaining legacy applications and her contributions to WordPress, Juliette is very specific about defending the reasons why it is OK to not migrate to the latest greatest. She also explained the hardship that comes along with not following the progression as there are now more and more packages, libraries and tools that no longer support older versions. This can be painful if you have a project that is required to support more PHP versions, like it is the case with WordPress.

Workshop: Migrating to PHPUnit 10

Workshop Migrating to PHPUnit 10

The workshop “Migrating to PHPUnit 10” was the sessions I was most eager to participate in. I was happy to learn that the changes between PHPUnit 9 and 10 are not that impactful and require not much work on my part to upgrade our projects.

Unfortunately I missed a bit of the workshop for another meeting, but all in all it was a great session hosted by Sebastian.


Michelangelo van Dam

Michelangelo van Dam is a senior PHP architect, PHP community leader and international conference speaker with many contributions to PHP projects and community events.