Chad Minick
Software Developer

PHP

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 ...

PHP frameworks are obsolete

As a person who works with the PHP support community quite a bit, I'm often asked "What PHP framework do you recommend?". I answer this as honestly as I can: "None of them". It does pain me to say this, but as someone who's been to the other side, and not only seeing that the grass is greener, it's like REALLY FREAKING GREEN. Now before I start getting hate mail, let me explain that I still think there is a market for PHP frameworks.  I think if you have a moderately low traffic site that's going to live on shared hosting, and is basically a CRUD application on top of MySQL, disregard this article, it probably isn't for you. However, I've seen so many projects start out with that scope. They either grow or the developer/client wants to add more fancy new features they are starting to see elsewhere on the web. Then I see all these PHP developers hacking things that the PHP stack really isn't meant to do. Of course there are add-on systems you can put on your stack to tackle these problems but they don't have full control over the systems and people seem to be reluctant to add a new system if they could JUST hack this ONE thing into their web app (that will summarily destroy their throughput of their web server). I will go over these add-on systems in a bit.

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, , ,

Shift Right Zero-fill in PHP

I found this on the internet, might come in handy.

<?php
function zeroFill($a, $b) 
{ 
    $z = hexdec(80000000); 
        if ($z & $a) 
        { 
            $a = ($a>>1); 
            $a &= (~$z); 
            $a |= 0x40000000; 
            $a = ($a>>($b-1)); 
        } 
        else 
        { 
            $a = ($a>>$b); 
        } 
        return $a; 
} 

credits to: Alex Stapleton, Andy Doctorow, Tarakan, Bill Zeller, Vijay "Cyberax" Bhatter, and traB.

Read More ...
September 29, 2009 Comments
Chad Minick | Software Developer
Twitter | Github | LinkedIn