PHP

PHP5 book review

Oliver Brown
— This upcoming video may not be available to view yet.

http://rcm.amazon.com/e/cm?t=galaxia-20&o=1&p=8&l=as1&asins=1590593804&fc1=000000&lc1=0066cc&bc1=ffffff&lt1=_blank&nou=1&IS2=1&f=ifr&bg1=ffffff&f=ifr

PHP 5 Objects, Patterns, and Practice

Put simply, after reading this book I finally “got” how to use OOP usefully in a web application. Too many OOP tutorials use examples of objects too abstract and literal to be useful (like animals or shapes). This book takes real world examples and explains what sort of things really should be objects and how to use them.

The book is basically split into three sections, as the title suggests. The first part is a very quick overview of OOP and the new features of PHP5. This is thankfully short (and as such this book is aimed at people with a fair bit of PHP experience).

The second section is the largest and basically goes through the most common design patterns and explains situations you’d use them in.

The third section is less focused on OOP and covers some practical considerations including version control and unit testing.

I would say this is probably the best book I’ve bought (except my first Perl/CGI book) and I recommend it for anyone who has to yet to be convinced about PHP as a robust OOP language.

Issues with extending SimpleXML

Oliver Brown
— This upcoming video may not be available to view yet.

I wrote a post about my attempts to extend SimpleXML to support microformats. Well it’s not as it easy as it seems.

You can’t define new properties of a class extending SimpleXMLElement. Well you can define them but they don’t work - when you access them they always return a SimpleXMLElement object (or actually an object of whatever class you defined).

I’ve tried overriding __get and __set and neither work so the only thing I can think of is to create a new class that delegates most of it’s work to SimpleXMLElement.

Microformats extension to SimpleXML

Oliver Brown
— This upcoming video may not be available to view yet.

I’m writing a PHP5 object that extends SimpleXML to automatically add various microformats. So you could do, for instance, the following:

$xml = SimpleXML\_load\_file('test.xml');
foreach ($xml->hEvent as $event) {
    print $event->original();
}

This would print the original HTML of every hEvent found in the HTML document. XML, PHP, PHP5, microformats, hCard, hReview, hCalendar

Code generation in PHP

Oliver Brown
— This upcoming video may not be available to view yet.

I’ve started working on a class-based code generation utility for PHP (in PHP). Like the scripting engine it’s working out simpler than I expected. Quite how powerful or indeed useful it could be is yet to be seen. The way it works is by allowing you to define fragments of classes. For example the Singleton fragment is:


class !className {
    static private $instance;

    private function \_\_construct() {
        // Code Start
        // Code End
    }

    static public function Init() {
        if (!self::$instance) {
            self::$instance = new !className();
        }
        return self::$instance;
    }
}

You create a class with some number of fragments. Each successive fragment adds specified method and properties to the class. If two (or more) fragments define the same method (probably common with constructors for instance) the the code for the second fragment get’s added in the //Code Start ... //Code End sections. Ultimately you will be able to change your model (defined in XML and it will update your code accordingly, maintaining all the code within the //Code Start ... //Code End sections.

How about Cash City Wars

Oliver Brown
— This upcoming video may not be available to view yet.

That’s the name I’ve come up with for the game since it’s vaguley based on Cash Wars. Or at least will be. I’ve started adding descriptions to towns. There are a few issues still though, most notably the existence of multiple towns with the same name which I am eliminating (I’m only intending to have the largest 100 towns).

Cash City Wars

Demo of GIS thing

Oliver Brown
— This upcoming video may not be available to view yet.

Here’s a work in progress version of the online game based on real geography idea I had. Demo.

New MPOG idea

Oliver Brown
— This upcoming video may not be available to view yet.

I was reading a tutorial on using PHP and GD with GIS data, that is how to draw maps with PHP using real life data. There has to be a cool way to make on online game out of this although I’m not sure what. I was thinking something along the lines of the old CashWars game…

Bad DOM

Oliver Brown
— This upcoming video may not be available to view yet.

The Dom Scripting Taskforce says adding non-standard markup to page using Javascript is OK. Well I wouldn’t call it a “best practice” but from a personal point of view I can’t see a practical disadvantage.

For me the problems with bad markup come from trying to parse it automatically (using PHP’s SimpleXML object for instance). Since the javascript will basically only affect the page a human sees and not a machine, many of the disadvantages of non-standard markup fade away.

PHP Security Checker

Oliver Brown
— This upcoming video may not be available to view yet.

Here’s an interesting utility (that most WordPress users will have seen already since it’s mentioned on the news part of the dashboard: a PHP Security Checker.

I’m not sure how it works; it sounds like it just scans PHP scripts and returns references to possibly dodgy bits of code. Donncha O Caoimh of Holy Shmoly! raised a point that I never really thought about - the security of WordPress themes. However much the creators of WordPress like to point out that their template files don’t require knowledge of PHP, that doesn’t mean you can’t put PHP in them to do whatever you like… Maybe this utility will help.

PHP tutorials

Oliver Brown
— This upcoming video may not be available to view yet.

I’m contemplating writing a mini-tutorial about OOP in PHP. I know there are many out there already but I have a friend in particular I’m trying to get to get to grips with this so he can help with parts of Galaxia Reborn (some parts are superbly modular; I may put the specs for such online and maybe have an online editing option of some sort for anyone who wants to help).

Either way writing a tutorial would probably be a good exercise as well as a good source of useful content .

“to get to get to” has to be a quote of the year or something.