When I was younger, I had strong opinions about many subjects. I felt I was right about a great many things, and anyone who disagreed with me was wrong. In my mind there was a right or a wrong, a black and a white, with little room for grey. Others were certainly entitled to their own opinion, but that didn’t make them any less wrong if their opinion differed from my own.
As I’ve gotten older, I’ve begun to realize in programming, and in life, so often things rely on a two word phrase that makes all the difference: it depends.
PHP more or less has two kinds of dependency injection available: constructor injection, and setter injection.
Constructor injection is the process of injecting dependencies through the constructor arguments, like so:
User experience matters.
Nowhere is this clearer than in the case of the accidental missile launch warning that was sent to all of Hawaii.
Here’s a copy of the the actual screen that was used by technicians to send out alerts of various types:
The other day I came across the following code in a project:
public function __construct(PDO $pdo)
$this->pdo = $pdo;
public function getAllUsers()
$stmt = $this->pdo->prepare('SELECT * FROM users');
Everybody likes “the new hotness.” Everyone loves a new car, or a new computer, or the state-of-the-art video gaming console. It’s why people camp out for days to get their hands on a new iPhone, when they could just buy one the next week off the shelf. People love to have the hot thing, right now.
Perhaps, then, it shouldn’t be so surprising that people get tremendously excited when a new version of PHP comes out. People look forward to the new features, whether they be the trailing commas in list() syntax or counting of non-countable objects.
When it comes to best practices, there’s always a healthy debate, and that’s never more true than in the PHP community. The “best practices” that have been written about, agreed upon and talked about don’t exist out of thin air, but are hard-won knowledge derived from experience, plus a little bit of not following best practices.
I want to talk a little bit about what PHP’s best practices are, where they come from, how you can get involved in the next generation, and the best way to use best practices in your day-to-day coding.