PHP

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
Never type hint on arrays

Let's be controversial: In modern PHP, you should never type-hint an array.

Before you start throwing tomatoes, hear me out.

Continue reading on Steemit

Larry 27 July 2018 - 10:18pm
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.)

The 3 paragraph pitch

Submitted by Larry on 20 October 2017 - 5:21pm

Earlier this week a fellow PHP public figure tweeted saying that I write great session proposals for conferences. After I finished blushing I reached out to him and we talked a bit about what it was he likes about them. (Whatever I'm doing right, I want to know to keep doing it!)

Based on that, I figured it would be educational to dissect how I go about writing session proposals for conferences and hope that conference organizers don't catch on to my tricks. :-)

Best practices are contextual

Articles, blog posts, and Twitter debates around "best practices" abound. You can't swing a dead cat without bumping into some article espousing the benefits of designing and building software a certain way. (Side note: What kind of sick person are you that you're swinging a dead cat around? Stop that! You're desecrating the dead!)

What nearly all of these articles fail to convey is that "best practices" are contextually-dependent. Always. For one, they evolve over time; really, there is no such thing as a "best practice"; There are "leading practices", which is an inherently changing and growing definition as the technology and market changes and as we as an industry learn more and discover new and exciting ways to royally screw up.

Larry 23 August 2017 - 5:51pm
PHP 7 Explained: A review

The team over at thePHP.cc recently published an ebook entitled PHP 7 Explained, "Everything you need to know about the next generation."

A few weeks back, I received an email from them stating "As a token of our appreciation for your involvement in the PHP community we would like to gift you a copy of our eBook." Yay, free stuff! Since I'd gotten it free, and it's of timely use to the PHP world, I decided to publish a formal review.

Disclaimer: I was not asked to write a review, although the authors did ask for feedback. The only compensation I receive for this review is the book itself, which was sent without the expectation of a review. Also to the authors, yes feel free to quote portions of this review on the books site as long as it's credited.

Larry 31 December 2016 - 1:50pm

New Drupal, new Platform, new PHP, new year

Submitted by Larry on 31 December 2016 - 12:19pm

OK, well, it took a while, but I've finally gotten my blog off of Drupal 6. :-) Welcome to the new and improved Garfieldtech.com! My blog is unsurprisingly rather bland, as it's, well, a blog. That made updating to Drupal 8.2 using the Drupal migrate module reasonably easy. It wasn't hiccup free, and a few not-yet-updated modules got lost along the way, but it wasn't an epic struggle, either. There were only two major hiccups:

Composer vs. Linux Distributions: A Mental Model Battle

Submitted by Larry on 24 February 2016 - 11:10am

Recently, Gentoo documented what they view as the Composer Problem: Basically, PHP projects using Composer can't be packaged the way they want to package it, with system-level shared libraries. This is not a new complaint; Other distributions have complained about Composer's impact before. But fundamentally I think the issue stems from having the wrong mental model of how modern PHP works when viewed from a distribution or sysadmin perspective.