Chad Minick
Software Developer

Coding

Option Pattern and avoiding Nulls pt. 3: Request Variables

In Part 1 I introduced the Option pattern as a pattern to avoid using nulls. In Part 2 I showed an example of how this can be handy in method chaining. In this part I'll introduce how to use Option for request variables.

Read More ...

Option Pattern and avoiding Nulls pt. 2: Method Chaining

In Pt. 1. I introduced Option as a way to avoid running into problems using null. Now to show you one of those problems. Consider the following method:

function isPass($student, $course) {
  $grade = StudentRegistry::getStudent($student)->getCourse($course)->getGrade();
  if($grade > 60) {
    return true;
  }
  return false;
}
Read More ...

Option Pattern and avoiding Nulls pt. 1: Introduction

I imagine in the PHP community, the idea of avoiding nulls in your code might be something new to think about. Because PHP is a dynamically typed language, nulls are handled much better compared to other languages. However, they do still cause a lot of issues. Two of the main places I see issues with nulls in PHP is method chaining and request variables. I'll make two more parts to this series to cover each. This is part 1: introduction to the Option pattern.

Read More ...

Reading Files in Reverse in PHP

Every once in awhile I get someone asking me in ##php on freenode how to prepend entries to a file. Usually it's because it's a log file of some sort and they want to read the latest entries first. This is usually for someone (not necessarily the developer) who isn't used to the whole habit of reading log files from the bottom up. Years of using tail to read log files has lead me to have different expectations than a typical Joe (not you, Chance), and wanting new entries first is a reasonable request. However, one has to remember that viewing data and storing data are two completely different things. The most efficient way to view data isn't always the most efficient way to store it.

Read More ...
August 12, 2010 Comments,

Simple PHP Template Engine

PHP is a bit of a rare language as it can already template into text in markup with zero modifications or libraries. It is probably one of the big contributing factors why PHP is one of the most popular languages on the web today. (Can't be the only factor, it didn't work for ColdFusion) Most other web languages have a one or more templating languages with a different syntax that need to be learned on top of the implementing language. PHP lowers the bar to entry by allowing you to put your PHP code right into your html. But as we all know, sometime in your PHP tour, you will realize the need to separate presentation logic and the application logic. Some developers go running to some other solution that provides a different syntax. I am a bit puzzled on why this seems to be common practice, PHP can provide the same features without throwing another template syntax on top of what PHP already does. You can still achieve the separation needed with a simple class (shown at the end of this article). Read More ...
September 30, 2009 Comments, , ,
Chad Minick | Software Developer
Twitter | Github | LinkedIn