Category: "PHP"

PHP - Catching session timeout issues

I've been working on a bug where an application is logging out unexpectedly. To identify the piece of code that is destroying the session namespace I've been using the code snippet: PHPob_start(); debug_print_backtrace(); $trace =&nbs… more »

Linux Command Line - Convert XML to JSON

This was the answer to a question that came in an email - "Do you know of a good XML to JSON converter?" Obviously you need php-cli, JSON, and SimpleXML. :) The "xml" is the name of the file that contains the XML, the output can be piped to a differe… more »

Upgrading PHP 5.3 to 5.4 - Checking your code (Linux)

If you are upgrading PHP from 5.3 to 5.4 for an existing application, you can use the following commands to check for parse errors. Shelltree -fi application | grep -E '.php|.phtml' | sed "s/^/php -l&nb… more »

Create a PHP class from a database table

Simple script to get the columns from a database table and write out a PHP class. PHP<?php$table = preg_replace('/\W/','',$argv[1]);if (empty($table)) die ('Invalid table'.PHP_EOL); try {   &#16… more »

PHP - Sorting Objects - Performance Considerations

PHP has some great functions for sorting arrays, however, they should be used with care. If you have an array of complex objects and plan to sort only on one value, you may see significant performance gains if you flatten the array into a single dimens… more »