Software Engineering in WordPress, PHP, and Backend Development

Tag: PHP (Page 12 of 12)

A Primer On Reflection in PHP (And How It Plays Into Unit Testing)

For the past few weeks, I’ve been writing about unit testing for the members of the site (and something that I plan to continue doing in the next post). It’s something that I think; if you write server-side code, you should be doing.

Of course, it’s easier for me to say it than do it so although I try to make sure I do a good job of it, there’s always room for me to improve. I say that more as a personal gut check than anything else, so I digress.

One of the concepts that often come up during testing is the idea of testing the values of private attributes. For example, let’s say that you have a setter, but you don’t necessarily have a getter for that particular value.

It’s easy to say “Well, then you need to write a getter,” but that’s not always the case. I mean what if you’re storing some information within the class that doesn’t need to be exposed to third-party classes?

How then are we supposed to write tests against that kind of data when we want to access it but don’t have the ability to do so and don’t want to compromise the integrity of our work?

That’s where reflection comes into play.

Continue reading

Learn The New Thing! (Wait, Not So Fast)

One of the things that I dig about the software development industry (others, too, but this is where we are, right?) is that it requires some degree of constant learning.

For some, that can induce a level of fatigue. And I get it because I’ve felt it. I don’t know if it’s an age thing (I’m not old, yet, but there’s a lot to be said from going from just yourself into an apartment into a house and a family, but I digress). I think that comes with a bit of thrashing is continually trying to keep up with every new thing that comes out.

The thing is that the further I get into my career, the less I’m interested in the learning The New Thing the moment it’s released.

The New Thing: Prototype

Remember when this was The New Thing?

And I say this knowing full well it’d be easy to dismiss what I have to say since I’ve written on going deep rather than wide with technology.

But this is a bit different.

Continue reading

How to Exclude Files From PHP CodeSniffer

When you’re working with PHP CodeSniffer, and you’re doing so in the terminal, you’re likely looking to output errors into something other than your IDE.

I mean, if that were the case, you’d just have it running in your editor, right?

But there are times where you may be interested in finding the problems in other people’s code. Perhaps it’s a dependency, perhaps it’s a third-party piece of software, or perhaps it’s a favor.

Whatever the case, if you’ve set up the project directory in a way that uses Composer to include PHP CodeSniffer and you’re using the WordPress Coding Standards, then you’re likely going to need to exclude files from PHP CodeSniffer when running the program.

And this is how you can do that.

Continue reading

Working with PHP Sessions and WordPress

Earlier this week, I was talking with a friend and fellow developer about how I handle sessions in WordPress. Specifically, we were talking about how we take PHP Sessions and WordPress and make them work together (or how we adapt the former into the latter).

This is occasionally a point of interest for WordPress developers since WordPress, as an application, is stateless.

The neat thing, though, is that it gives us a variety of ways to approach this problem. But we’re not the first (and we definitely won’t be the last) to come across this problem.

Continue reading

Touch a File (Before Creating It)

If you do any type of WordPress development for clients, then you’re likely familiar with having to work within many different environments.

Sure, the backend of each system may be very similar: That is, they are all running on some form of Linux with Apache or Nginx and MySQL. But, depending on the project that you’re working on, you may end up facing a variety of file permissions.

For example, let’s say that you’ve been hired to write a plugin or some custom functionality for someone and the work that you’re doing has to integrate with work that someone else has done. On top of that, it has to integrate with permissions on a file system that you can’t change.

Furthermore, a portion of the work you have to do must write a file to the disk. The problem? The code for saving a file isn’t working.

What then?

Continue reading

Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑