Category Archives: PHP

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 … Continue reading

Posted in PHP, Programming | Leave a comment

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, … Continue reading

Posted in PHP, Programming | Leave a comment

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 … Continue reading

Posted in PHP, Programming | Leave a comment

PHP 5: Class hinting

Class hinting is where the class of object to be passed into a method is specified in the function call. e.g. abstract class User { protected $logState; public function User() { $this->logState = new LogState() } public function setLogstate(LogState $logState) … Continue reading

Posted in PHP, Programming | Leave a comment

PHP 5: Interfaces

Interfaces are a way of adding the definition of extra methods onto a class to force it to conform to a particular pattern. An interface consists entirely of methods with empty bodies i.e. abstract methods: interface Saveable() { public function … Continue reading

Posted in PHP, Programming | Leave a comment

PHP 5: Static classes

Static classes are used for utility scripts that (in the past) would have been in common functions or held global variables. The advantage of using a static class is more to increase code readability (and ease of debugging) than for … Continue reading

Posted in PHP, Programming | 5 Comments

PHP 5: Abstract classes

Abstract classes are used to define operations and parameters but where you do not want a class instantiated directly. An abstract class must, therefore, have subclasses. In our example, we may not allow a type of general “User” but insist … Continue reading

Posted in PHP, Programming | Leave a comment