Category: PHP

Push Notifications on iOS

Push Notifications on iOS

As with anything new on iOS, getting push notifications working has been a pain. Thankfully, there’s a brilliant write-up of the process here: Apple Push Notification Services in iOS 6 Tutorial: Part 1/2. Plus the PhoneGap/Cordova plug-in to make it all work here: phonegap-plugin-push.

DomDocument::loadXml not throwing exceptions in PHP

DomDocument::loadXml not throwing exceptions in PHP

For some reason, Zend have decided not to make PHP throw an exception when you try and load invalid XML into a DomDocument object. This includes XML with invalid characters e.g. &. This means wrapping a try/catch around anything does absolutely no good whatsoever, which is annoying. Is there a good way of trapping runtime …

+ Read More

PHP aaaaarrrrrggggghhhhhh

PHP aaaaarrrrrggggghhhhhh

Things I hate about PHP No. 512 (notwithstanding the fact that in comparison to many other things I like PHP): Inconsistency in parameter ordering Say I want to find a small thing in a big thing, like a piece of a string in a bigger string. I can use strpos and you pass in the …

+ Read More

PHP 4 foreach as references

PHP 4 foreach as references

PHP 4 doesn’t seem to create references for objects in foreach loops. e.g. the following will not change the original objects: foreach($placeholder as $contentBlock) { $contentBlock->setPosition(1); } The value of the position property in the original object will remain unaffected. This is quite rubbish. To get round it you need to get all the array …

+ Read More

PHP 4 annoyances ( = rant)

PHP 4 annoyances ( = rant)

After working with PHP 5 for quite some time now, I’ve had to go back to PHP 4 to develop a CMS for a client’s site where we don’t have much over the hosting environment. Going back to the old version has annoyed me quite a few times already and it’s probably made worse by …

+ Read More

PHP 5 Static class variable inheritence

PHP 5 Static class variable inheritence

PHP 5 doesn’t seem to attempt to implement any kind of inheritance for properties within static classes. This can be mean having to duplicate code within static subclasses. As an example, we would like to have a parent class (this is using the Singleton pattern) such as this: abstract class DataTable { protected static $instance; …

+ Read More

Using importNode and appendChild with PHP 5 DOM

Using importNode and appendChild with PHP 5 DOM

importNode is one of the DOM functions in PHP 5 that I struggled with for a while. What I wanted to do was to take an XML node from one document and insert it into another, and somehow that wasn’t particularly easy. I tried using ‘appendChild’ but kept getting ‘wrong document’ error messages. Once it …

+ Read More

Using removeChild with the PHP 5 DOM

Using removeChild with the PHP 5 DOM

The documentation for PHP 5’s DOM functions isn’t at its most helpful yet, so I thought an example of how to use ‘removeChild’ wouldn’t go amiss. Assuming first that you have some DOMDocument XML in a variable called $xml, that may look something like this: My title The first thing to do is to get …

+ Read More

PHP loop benchmarking

PHP loop benchmarking

This benchmark of different ways of looping over a hash array is very interesting. Some things aren’t too surprising, such as counting the elements in an array before looping over them is faster than not counting them, could be expected, but it’s good to see how fast the built-in functions run. PHP loop benchmarking

PHP 5 and the magic __toString() method

PHP 5 and the magic __toString() method

Working with PHP 5 I thought the ‘magic’ method __toString would be a really great way of substituting objects for simple data types. That seemed the whole point of good object oriented design, so I could change the way a piece of data worked without having to track down every call to it and change …

+ Read More