PHP5

PHP custom debugging functions

Here is another debugging helper for Symfony, CodeIgniter, Kohana and Zend frameworks or your applications. Normally you would use var_dump() or print _r() for debugging but dumping the data without xdebug always a pain.

I use these custom functions depending on type of data whether an array or a class to debug my code which makes it more friendly and human-readable.


<?php

function my_print_r ($param, $bool = TRUE) {
    pre( print_r($param, $bool), FALSE);
}

function my_var_dump ($param) {
    pre(var_dump($param));
}

function my_debug ($param) {
    if (is_object($param)) {
        pre('Object: ['.get_class($param). '] => '
           . print_r(array_keys(get_object_vars($param)), TRUE), FALSE);
    }
}

function my_debug_in ($param) {
    if (is_object($param)) {
        pre('Object: [' .get_class($param).' ] => Array', FALSE);
        foreach (get_object_vars($param) as $key) {
            my_debug($key);
        }
    }
    if (is_array($param)) {
        my_print_r($param);
    }
}

function my_class($name = NULL) {
    $class = new ReflectionClass($name);
    my_print_r(Reflection::export($class));
   
}

function pre($param, $bool = TRUE) {
    if (!ini_get('xdebug.default_enable') || !$bool) {
        echo "<pre>".$param ."</pre>\n";
    }else {
        echo $param;
    }
}

?>

Trip planner API in PHP

Trip Planner is an API written in PHP5 demonstrating the abstract, factory and singleton design pattern.

The API can create and sort various transportations and provide trip steps from a point A to point B via several stops on the way also handle the requests over start point, current step or end step also combinations of all. Each step can contain information about seat assignment, and means of transportation such as flight number, bus number etc...

Transport example:

Abstract class Human extends Animal implements God

The code junkie only can live in code-land.
<?php

abstract class Human extends Animal implements God

     public static 
$humiliation

     final function 
believe(); 



?>