Posts in:
PHP

Refactoring in Practice

I love taking larger functions and slimming them down into a more efficient and readable format. Here is a simple example of just that. The original function: function strip_slashes( $data ) { if( is_array($data) ) { foreach($data as $key => $val ) { $data[$key] = strip_slashes($val); } } else { return stripslashes($data); } return $data; [...]

Directory Listing from a Path

$path = dirname(__FILE__); $listing = array_filter(scandir($path), function($var) { // remove special directories ‘.’ and ‘..’ from listing if( preg_match(‘/^[\.]{1,2}$/’, $var) ) { return FALSE; } // remove files from listing if( !is_dir($var) ) { return FALSE; } return TRUE; }); This is a little snippet of code I’ve been using a lot recently. This function [...]

Turn on Error Reporting

It’s PHP 101, yet so many developers fail to remember it. display_errors = On error_reporting = E_ALL | E_STRICT Always enable the display of errors on your development server, disable them on the live server. Showing all errors will help you find those stubborn programming mistakes quickly. Set these options in your php.ini file.