PSR-14: A Major Event in PHP

Submitted by Larry on 26 March 2019 - 10:44am

The PHP Framework Interoperability Group has released a number of new specifications in the last year. The latest, PSR-14, covers Event Dispatching. Like many PSRs it's a fairly small spec, at the end of the day, but intended to be high-impact.

In this series of posts I want to cover what PSR-14 is and does (and what it isn't and doesn't), and how to best leverage it in your projects as it gets deployed more widely.

Continue reading this post on SteemIt.

In defense of the office

It is trendy these days to extol the virtues of remote working, and either implicitly or explicitly shame any company/manager that doesn't like it. While there are absolutely advantages to remote work or working from home, the one-sidedness of the conversation is, I believe, actively harmful. The idea of "going to work" is still a valid and useful one, and one that should not be cavalierly cast aside in Twitter snark the way it currently is.

Continue reading this post on SteemIt.

Larry 24 February 2019 - 2:49pm

When I started writing PHP...

Submitted by Larry on 12 February 2019 - 7:46pm

I don't know exactly when I started writing PHP. It was shortly after the start of my second quarter of my freshman year of college, when a newly-met friend of mine introduced me to PHP as an easier to understand alternative to Perl. That puts it, I think, somewhere in January or February of 1999.

20 years ago, give or take a week. I have been writing PHP for two decades. That's more than half my lifetime. I feel old.

I thought it would be amusing (mostly at my expense) to look back a bit on just how much the PHP world has changed in the last two decades.

Continue reading this post on SteemIt.

Announcing API Problem 3.x for PHP, complete with PSR-17 support

Submitted by Larry on 24 November 2018 - 6:06pm

After a longer than intended delay, I'm happy to announce the 3.0 release of my Crell/ApiProblem library.

ApiProblem is a small, self-contained library for modeling IETF RFC 7807 "Problem Details" messages. (I know, more gibberish.) That is, it makes it easier for PHP developers to build a message for their API servers to handle cases where Something Bad Happened(tm).

Continue reading this post on SteemIt

Don't use mocking libraries

I am all for testing. Whether you always write unit tests in advance as Test Driven Development (TDD) advocates call for, write them after, write them alongside, a little of each, I don't care. Tests are your friend. You want tests, and specifically you want good tests.

There's a lot of opinions on what constitutes a "good" test, of course, and much is subjective to the type of code you're working on. However, since the release of PHP 7 I've found that while writing tests... I am never using a mocking library. In fact, I'm going to go as far and say that

You should never use a mocking library in PHP 7.

Before all of you gasp, clutch your pearls, and send ninja hit squads after me, let me justify that position.

Continue reading on Steemit

Larry 14 September 2018 - 6:25pm
PHP: Use associative arrays basically never

The other day I was working on some sample code to test out an idea that involved an object with an internal nested array. This is a pretty common pattern in PHP: You have some simple one-off internal data structure so you make an informal struct using PHP associative arrays. Maybe you document it in a docblock, or maybe you're a lazy jerk and you don't. (Fight me!) But really, who bothers with defining a class for something that simple?

But that got me wondering, is that common pattern really, you know, good? Are objects actually more expensive or harder to work with than arrays? Or, more to the point, is that true today on PHP 7 given all the optimizations that have happened over the years compared with the bad old days of PHP 4?

So like any good scientist I decided to test it: What I found will shock you!

Continue reading this post on Steemit

Larry 30 June 2018 - 3:59pm

Quick and easy PHP code generation testing

Submitted by Larry on 22 June 2018 - 8:40pm

Recently I was working on some PHP code (for the PHP-FIG) that involved code generation. Lots of systems these days are doing code generation (compiled dependency injection containers, ORM classes, etc.), but surprisingly I've avoided having to touch that code myself until now.

Of course, like any good developer I was writing tests for it as I went. That meant needing to test that the generated code was valid PHP syntax and did what I wanted it to do.

(Continue reading this post on Steemit.)