Latest stories

How to safely handle PHP “__toString() must not throw an exception”

Because there is no safe way to handle an exception thrown during __toString the easiest workaround for this is to catch all exceptions thrown and return either an empty string or null.
Since any invocation of __toString will expect a string back, it is a graceful way to handle any under-the-hood errors if you’re using __toString as a shortcut to echo out objects.

What does vagrant up do, where does the box get downloaded to?

Vagrant is a pretty nifty tool that simplifies developing on a Virtual Machine. However it is sometimes not obvious what happens in the background! An example of this is where your VM’s actually get downloaded to, and how they are managed. Since Vagrant acts as a wrapper for VirtualBox (or VMWare Fusion more recently) when you “add” a box, it essentially downloads a pre-built...

Convert non-Java Eclipse ADT project to Android project

If you’ve imported a project into Eclipse, say from Git for example, then it might not be set as an Android project. There doesn’t seem to be an easy way to convert the project to an Android project through Eclipse itself, but you can change the nature of the project by editing the project XML file. Close the project in Eclipse Open .project in a text editor Assuming...

“Your proxy directory must be writable”

When you first start off with Doctrine 2, you’ll eventually start creating complex objects with child objects as properties, which of course you will use Doctrine to load. Unlike how you’d do it traditionally though, Doctrine uses proxy pattern objects to lazy-load these child objects until they are accessed; these objects are cached, and thus the proxy directory just like the cache...

“The class ‘x’ was not found in the chain configured namespaces”

If you are getting a namespace chain error when trying to load entities with Doctrine 2 in Zend Framework 2, it is likely because as far as Doctrine is concerned the namespace your entity is in is missing. If you’ve copied Jason Grime’s Doctrine 2 and Zend Framework 2 tutorial then you’ll notice the configuration he places in module.config.php array( 'doctrine' =>...

RIJNDAEL encryption with PHP, 256-bit using IV

I had a bit of trouble finding a how-to of how to encrypt and decrypt using RIJNDAEL, so I put together a quick example of how to using a non-blank IV. However I did find a useful code snippet from Chilkat Software that helped me a lot of the way. The only gotcha I found is that if you generate an RIJNDAEL 256 CBC key and IV using OpenSSL it will generate a 64-bit key and 32-bit IV, even though...

How to install CentOS 6 on Microsoft Hyper-V virtualization

Many developers rely on Linux, but often work in a Windows infrastructure environment. Often it’s not feasible to install a flow-blown VSphere or XenServer setup when everything else runs on Windows Server and there’s limited hardware, but virtualization has many advantages. Enter Hyper-V, which can be looked after by Windows system administrators, but let you use Linux in virtual...

Get Android stack trace from device using Debug Bridge

Instead of crashing, sometimes your Android application will stop responding and dump a stack trace to the device. You probably will not be able to access this using Android File Transfer, and if you view it using the Dalvik Debug Monitor Server (DDMS) the data directory will probably appear empty. You can get the file using the Android Debug Bridge (ADB) however. The easiest way to set this up...

Using ZFDebug for Zend Framework with database and cache

ZFDebug is a Zend Framework plugin to debug and analyse your web application as it bootstraps, so that you can see how long everything takes to load, including how many database and cache calls are made. Having used ZFDebug in the past, it’s a handy tool but somewhat light on documentation. Here is a simple way to set it up to debug your database and cache calls, which should be placed...

Using Zend_Pdf and Zend_Pdf_Image with remote URL’s (files)

Zend_Pdf is a handy component of Zend Framework, but expects you to use local files. However if you need to open files that are located on a different server (such as an Amazon S3 bucket) you will need a way of getting them into Zend_Pdf first. $pdf = Zend_Pdf::load($pdfUrl); One solution is to stream them in via a string… $pdf = Zend_Pdf::parse(file_get_contents($pdfUrl)); Similarly, if...