Garfieldtech

Technical thoughts, tutorials, and musings

Blog

PHP Tricks: Lazy public readonly properties

Posted:

I am apparently late in coming to this trick, but PHP 8.1 is going to make it even nicer to use.

A clever trick

There's an interesting intersection of functionality in PHP:

  • Declared object properties are more efficient than dynamic ones, because the engine can make assumptions about what data type to expect.
  • The magic __get() and __set() methods trigger when there is no property with a given name that has been set.
  • Fun fact: A property that has been declared but not initialized with a value is still technically "set"... to uninitialized.
  • However, you can unset() an uninitialized property.

That means you can do clever tricks like this (and some systems do, internally):

Fun with PHPUnit Data Providers

Posted:

Most PHP developers are familiar with PHPUnit these days. It is the most widely used testing framework for PHP by a wide margin (although others do exist). One of its more under-utilized features, though is data providers.

Data providers are a PHPUnit feature (and many testing frameworks have an equivalent) that lets you run a single test method multiple times but with different data. Often it's presented as a way to save typing, but I find it is also a useful architectural tool, too. And there are ways to use them that are even nicer than what most people tend to do.

Forged in Fire is Positive Masculinity

Posted:

I've long been critical of the discourse around masculinity. For the archetypal right-winger, masculinity means machismo, at least mild sexism, the rugged loner individualist who picks a fight and never cries because Men Are Supposed To Be Strong(tm). For the archetypal left-winger, the word "masculinity" is simply never uttered without the word "toxic" before it, because anything that implies males and females are different at all is inherently misogynist and thus destructive and we must not allow differences to exist.

You can probably tell from my tone just how much contempt I have for both modes of discourse.

A large part of the issue is that the Left seems incapable of offering a coherent concept of masculinity that it doesn't deem "toxic" that is not defined in negative terms — not this traditional thing that is now negative, not that traditional thing that is now negative, etc. — or in terms that are traditionally viewed as feminine. That's not to say that femininity is bad, but if your answer to "what is positive masculinity" is basically "traditional femininity," then you don't have a useful answer.

The Right, meanwhile, doesn't offer an alternative at all, doubling down on the idea that emotionally cold, violence-prone, sex-obsessed tough guys is the one and only natural state for males, despite the blatantly obvious psychological damage that does to men everywhere.

If we want to have a meaningful and positive understanding of masculinity, then we need to have examples of it that we can collectively agree are good role models. There is some discourse on that, but far too little and it's usually drowned out by the loud-mouths on both sides.

I'd like to offer a case in point of positive masculinity for consideration: The show Forged in Fire.

The case for partials and pipes in PHP

Posted:

The Partial Function Application RFC is currently in voting, and right now it's a close vote to the negative. I wanted to take this opportunity to try and make the broader case for partial application and for its related RFC, the pipe operator, in a way that is more appropriate for a blog post than the RFC body (which is, by design, more concerned with the finer details of "what").

The main pushback on the RFC so far is that the benefits don't outweigh the cost of yet-more-syntax in the language. Which is a fair position to hold, albeit one I hope to convince you is incorrect. That is, I believe the benefits vastly outweigh the syntax and implementation cost.

Good technical writing is hard

Posted:

A few days ago, I randomly tossed this out on Twitter without context:

Technical writing requires assuming the reader is simultaneously highly intelligent and utterly ignorant, without making them feel like you think they're utterly ignorant.

That shit is hard, yo.

Someone asked for ideas on how to achieve that goal, and it seemed like a topic worthy of discussion so here we are.

One year of functional PHP; now in Russian!

Posted:

A year ago, I published my first solo book, Thinking Functionally in PHP. The reception has been extremely positive; almost everyone that's read it (that has bothered to talk to me about it) has found it clear, helpful, and enlightening. Mission accomplished!

To celebrate the one year anniversary of the book's publication, I am happy to make two announcements.

First, Thinking Functionally in PHP is now available in Russian! The translation is by Alexey Pyltsyn, who is responsible for the Russian translation of the PHP documentation as well as numerous other tech book translations.

Second, to celebrate the anniversary both the English and Russian editions are now on sale! For today and tomorrow, the minimum price for the English version has been reduced to just $20 USD. The Russian edition's introductory price for the next week is only $10 USD. (Both prices are only through those coupon links.)

If you haven't picked up a copy yet, now is the time. If you have, it's a great time to gift a copy to a friend or colleague. :-)

I made a TYPO

Posted:

I am a firm believer in "anything worth doing is worth doing right." So when given the opportunity to get paid to do that, it's hard for me to say no. Which is why I didn't.

I am happy to report that this is my first week in my new role as Staff Engineer on the TYPO3 core contributors team.

The era of the Linux desktop is here. Ish.

Posted:

I've been a Linux user for 20 years, and Linux-primary for about 15 years. That puts me in the minority in most groups, even among developers who these days are still mostly Mac-o-philes if they're non-Windows. For that entire time, it's been a running gag that "this will be the year of the Linux desktop." And, of course, it never is. Whatever that means.

Guess what, we're now in the age of Linux. On the desktop. But it's not what you thought, and probably not what you wanted.

The Flag of Treason

Posted:

Last week, the unthinkable happened.

Well, I shouldn't describe it like that. Thousands of people thought about it enough to make it happen, millions of people supported it, and many observers had been warning about it for weeks. Clearly it was on people's minds. But that doesn't make it any less incredible.

The President of the United States instigated an armed coup and assault on Congress, specifically and explicitly to disrupt an otherwise boring procedural footnote in the process of replacing him as President. The Capitol building was invaded and sacked for the first time since 1814.