CategoryPHP

PHP related information

Late Static Binding namespace resolution in PHP

If you try to get the namespace of the child class that you are in using the __NAMESPACE__ keyword, you will have the same problem that you do using functions like get_class() in that you will get the namespace (or class) where the current method you are calling is defined. $namespace = __NAMESPACE__; $class = get_class(); You can use get_called_class() to resolve this for Late Static Binding...

Capistrano website deployment with PHP Composer

Composer is great for handling PHP dependencies, and Capistrano is great for automated deployment, so wouldn’t it be great if you could use them together? To do this, all you need to do is update your recipe with the following task, then add a hook to make it run when the recipe is used. To add the hook, make sure that Composer is triggered after finalize_update (which means it will happen...

PHP Startup: Unable to load dynamic library ‘/usr/lib64/php/modules/module.so’

For some reason (I think just on Red Hat/CentOS) you may end up with a bad reference in mcrypt.ini so “module.so” as opposed to “mcrypt.so” To update this simply edit mcrypt.ini so that it points to the right extension (instead of what I’m assuming is placeholder text) vim /etc/php.d/mcrypt.ini You should see the following… ; Enable mcrypt extension module...

Concrete5 “Fatal error: Class ‘View’ not found”

Concrete5 may present you with the confusing error “Fatal error: Class ‘View’ not found”, which looks like a Loader issue but often it is not. When moving between different servers, the database permissions may not be quite right, which will cause this to happen. If you check that the user that Concrete5 is using has access to the database and the correct credentials, then...

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.

“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...

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...