If debugging is the process of removing software bugs, then programming must be the process of putting them in.
Edsger Dijkstra

PHP Micro-Framework

Few days ago I was searching for a RESTful PHP framework to help me develop a little project of mine. As I was searching, I stumbled upon PHP micro-framework. At first I didn’t know what that means, but as I dug deeper I saw some new ideas, new ways to develop a web application.

As you know, I have experienced with several PHP frameworks before, but all of them have many things in common: MVC, Controller-Action mapped to route, etc. When I read about micro-frameworks, they don’t enforce you to any fixed architecture. You could build your own architecture, they only provide the basics such as routing and database wrapper, thus the name “micro”.
Read the rest of this entry »

October 25th, 2011 PHP Tags: , , 1 Comment 278 views

I’m Back

I can’t believe how long has it been since I last post something here. Well I got this job that has been draining my time away from writing anything. Either that or I am just too lazy :|.

Anyway, now I think I have something to write about so I’ll start with writing a post about I’m coming back to this blog. And this is that post.

Next? I’m thinking about micro-framework.

October 25th, 2011 Uncategorized Tags: 0 Comment 69 views

Block Comment

We all know what a block comment is, sometimes we use it to comment a bunch of lines of code. And sometimes we might want those lines of code to be uncommented and commented again. In a traditional way, we need to make two modifications each time, at the beginning and at the end of block comment symbol.

For example:

usual_code();

sometimes_unused();
sometimes_unused_too();

another_code();

If we want to comment some lines:

usual_code();
/*
sometimes_unused();
sometimes_unused_too();
*/
another_code();

We modified two spots. Now, I prefer to do just one modification each “toggle” (comment-uncomment switch), so I use this:

usual_code();
/* Some description
*/
sometimes_unused();
sometimes_unused_too();
/**/
another_code();

To comment them:

usual_code();
/* Some description
     <-- only need to delete this part, one spot
sometimes_unused();
sometimes_unused_too();
/**/
another_code();

More efficient. IMHO.

May 25th, 2011 Programming Tags: , , 1 Comment 245 views

Say No to “global”

In PHP, a function (or class method) could use variables that reside in the global scope by explicitly stating them with global keyword. For example:

$string = 'an apple above the head';

function break_string() {
  global $string;
  return 'break ' . $string;
}

This practice has some disadvantages, one of them is we can’t directly know the origin of the global variables. Let’s say we have this code:

include 'common_function.php';
include 'pedicure_function.php';
include 'medicure_function.php';

function break_string() {
  global $string;
  return 'break ' . $string;
}

Can you know where is the origin of global $string? We need to look through each of those included files and search for variable $string which resides in global scope. This might take some times, so I propose a better way to utilize global variables. Read the rest of this entry »

May 12th, 2011 PHP Tags: , , , , , 0 Comment 343 views

Simple PHP Class to Generate XML Document

Recently I need to generate an XML document with PHP. Since it’s just a simple task of generating a form of string, I don’t use any XML parser library. So, I create this PHP class which eases me accomplishing that task. It uses PHP Magic Method to generate the XML.

Let’s look at the code: Read the rest of this entry »

March 18th, 2011 PHP Tags: , , 0 Comment 540 views