Tag: PHP

OOP-NOOB Series – The Publicity Stunt

OOP makes use of access modifiers to control the accessibility of methods and properties. This is what allows you to use the concept of encapsulation, so that you have a public interface that consumers of your code can develop against, as well as a private implementation that needs to be treated as a black box from the outside.

Having all of your methods and properties be public generally defeats the purpose of using OOP in the first place, as most of the benefits depend on the concept of encapsulation in some form or other.

Read more →

Structuring PHP Exceptions

While the consensus is to use exceptions instead of errors, there is very little information on how to structure and manage them in a larger codebase. In this article, I want to talk about the way I currently set them up and use them in PHP, in the hopes to spark some discussion on the topic and get further feedback.

Read more →

Adding Git Hooks Through Composer Dev-Dependencies

I have been working on refining my development workflow for some time now, in order to optimize the quality of my code. And as I am a big fan of automation, I tend to look for tools that just do their work in the background and only need my input when my mental processing power is truly needed. This leads to a greater focus on the coding and problem solving area of development.

One of the areas that was missing a satisfactory solution so far was the pre-commit checks that git was doing when new changes were committed to a repository. I had a bash script that was provided with my code, together with a small instruction in the README.md file that was explaining how to symlink that file into the .git/hooks folder. It did work, but it needed manual interaction first in order to be able to do its work.

Read more →

Attracting Developers To WordPress

Ryan McCue, Senior Engineer at Human Made and WordPress Core Developer, has posted a series of tweets regarding the fact that WordPress is far from an ideal platform for developers, which has spawned a lot of discussion.

As a long-form response to this, here’s a list of changes I would like to see in WordPress, and how I would try to address backward compatibility (BC) concerns. I don’t pretend to know that this is the absolute best way to tackle the problem, this is purely my own biased opinion, and how I would try to fix the issues if I were in charge.

Read more →

Type Declarations using Interfaces in PHP

I’ve recently completed a preliminary code audit on an existing WordPress plugin, and one of the goals I’ve set for that audit was to decouple the code from the JavaScript library it was using, so that it could easily be extended to support future versions of that library.

A question came back about the constructor syntax I was using, and how that actually worked. I’ll use the opportunity to write the answer in form of a blog post, as I think that this is a concept that might be new to a lot of WordPress developers.

Read more →

PHP Feature Detection Library

Link to GitHub Repository: PHPFeature

I had a short conversation on Twitter the other day with Andrey Savchenko ( @Rarst ). He was wondering whether feature-centric PHP requirements would work in WordPress extensions.

Although he was talking about the features of the “WP extensions”, I asked myself why there was no feature detection library available for PHP, similar to what Modernizr does for the browser features. Traditionally, PHP requirements are always based on a version number constant.

Read more →