PHP Best Practices

There’s a new thread started over at phpwomen.org about best practices for programming with PHP, which will make interesting reading for anyone looking to improve their skills. I’ve been really brave and contributed one of the articles, PHPDoc: Comments are your friends.

People are all contributing a little knowledge about the area they feel comfortable with and even at this early stage the results are impressive!

PHP Throwdown Icon

As you may remember we participated in the PHP Throwdown a while ago. Well Elizabeth has sent out the icons to competitors who successfully got through the 24 hours and submitted something which vaguely conformed to the rules. You can see ours on the left :)

Does PHP know itself?

I’ve run into a problem with a framework I’ve been contributing to. It has a bunch of objects, which look a lot like rows in database tables. So there are pages and each page object is a row in the “pages” table in the database, with a primary key called “page_id”. There are also sections and each section object is a row in the “sections” table in the database with a primary key called “section_id”… you get the picture.

So there’s a parent class called “Model” which figures out the magic table/primary key names in the constructor and can then do a variety of tricks on the generic data set. The various object types such as page then extend this “model” and use its methods. Which was going quite well until I tried actually calling the methods.

Statically.

Because I figured that even if the code was inherited from somewhere else, PHP would know which class had called it in the first place and so I’d be able to reference “self” and know what was happening. So wrong!!

Its a feature of PHP that in fact the self() object for a method called statically will always reference the place the code is actually executing. So in order for me to statically call a method which is going to return me an array of instantiated objects of whatever type I called the method against (still with me??), I must first instantiate an object of that type and call it in the usual way.

So in case you’re wondering what the variables $pointless_page and $pointless_section are doing at the top of my script then now you know! I love the little quirks that programming languages have …

Hopeless Homeless

I may have mentioned that we’re buying a house, or houses … if that doesn’t sound familiar you should probably catch up and then come back to this page. So, to recap, the house isn’t falling down.

What I didn’t mention, because I didn’t know when I wrote that post, was that the final valuation of the house was subject to a satisfactory damp survey. The surveyor wasn’t happy to set a market value without a better idea of how damp-proof the cellar of the house was.

This is quite a long post, if you’re not feeling patient then just skip to the last paragraph at this point.

So, we commissioned a damp survey, some very accredited people that the estate agents had dealt with before. Its a house with a cellar containing a kitchen and a bathroom with little ventilation and no central heating, we knew it was damp but we thought some drying-out and better management of the space would help. The survey report recommended that the cellar be completely gutted, false walls and floors fitted, and sumps and pumps to deal with the moisture. At a cost of around 20,000 GBP. If pounds sterling isn’t your local currency then go and convert the numbers. It’s a year’s salary. It also excludes the cost of removing all wall and floor tiles and extending all electrical and plumbing features (so they reach past the new walls) and then refitting the large kitchen and the shower room.

So the damp survey went to the valuation surveyor and the valuation got smaller by the aforementioned 20k. The valuation went to the bank and our mortgage got smaller by the same amount … and so did our offer on the house.

Our revised offer has been refused. The vendor has put the house back on the market and asked for a copy of the damp survey. I feel like everyone else in the world can do do this right, get their foot on the ladder, be normal, and we can’t!! Anyway it looks like our stuff stays in boxes for a while longer …

One Pair of Fingerless Mitts

Just finished – and just in time as we’ve had snow here the last few days – my latest project! I knitted “fetching” from knitty.com, here they are:

(and yes, one little finger is always a bit crooked. The other one matched it until it got hit by a high-speed netball a few years ago)

I’m so proud of these little gloves, they were knitted on four needles – and with cables too!! The tension is a bit tight on the bottom of the first one that I did, I hadn’t knitted on four needles before and it was really slippery wool and I was struggling. Its Debbie Bliss Cashhmerino Aran and well worth the expense, only needed one ball so I’ve one left to make something else … suggestions please!

I should mention that my knitting had the right side on the inside of the tube when I knitted on the four needles. Apparently its supposed to come out on the outside so you can see what’s happening before you finish the item and can turn it the right way out but I couldn’t work that out without poking my eyes out with some of the needles at the same time :) Thanks to my knitting group friends for telling me to knit whatever way worked and especially thanks to mum for picking up and knitting the thumbs for me :)

Naturally Curly Hair

I had to post this, I’ve just lost an hour of my life on this website for people with curly hair naurallycurly.com. I’ve got hopelessly curly hair and lots of it so I can see me being a regular visitor to this site. As always, good to know I’m not alone!

The internet is great for that, whatever you are doing someone else is doing it to. What’s your favourite community site?

Open Office Custom Colours

Yesterday I was working on a document in Open Office and wanted to colour the background of some cells to match a diagram I had created1.

The choice of colours wasn’t great and there wasn’t a “more colours” button. After a few minutes of growling I went to Tools -> Options … and clicked on the colours menu item. Lo, and behold.

Not only can you add colours but you can completely alter the available colours for the grid. I can imagine this being a really useful tool for adding presets to assist with corporate branding or other situations where continuity is important and you don’t want to pick a non-corporate shade of green at any point when creating a document!

That’s my nice-software-touch of the week, what’s yours?

1 Dia is my diagramming program. Its interface is great, but its unlike anything else so expect to have to work at using it to start with.

Tiny Vim on Ubuntu

A new installation of Ubuntu exists at work and I’ve discovered that by default, it doesn’t come with real vim. The clue is in the error message:


E319: Sorry, the command is not available in this version: syntax enable

E538: No mouse support: mouse=a

To get things back to normal I needed to install vim and then alias it correctly. Using


which vim

I discovered that /usr/bin/vim was being used – this symlinks to /etc/alternatives/vim and that in turn links back to /usr/bin/vim.tiny. So I installed vim:


sudo apt-get install vim

and then changed the symlink in /etc/alternatives to point to /usr/bin/vim.basic instead – much better :)

Handknitters Handbook

A while ago my not-mother-in-law bought me this book and its been great so I had to sing its praises here.

Its not glossy or colourful, in fact the illustrations are two-colour, but its really useful. I’ve recently come back to knitting from crochet and I live some distance from either my mum or the book-donor so it can be hard to get a helping hand when I need one. This book is a knitting textbook and a great reference when a pattern calls for something fiddly to happen!

Watch this space for my latest (rather complicated) knitting attempt :)

PHP register_globals is ON

I started writing PHP when I was at University, in 2001 or thereabouts. Having checked the dates it looks like I did technically write PHP before PHP 4.3 was released and register_globals went out of fashion. I don’t recall it though and obviously its been a while!

Today I was trying to debug a script which uses register_globals on, virtually for the first time. Its a new working environment for me and a situation where support is still being provided for some legacy systems. Trying to track where values are coming from, or might be coming from, was quite mind-bending. Its like having voices inside my head while I’m trying to concentrate on something!

There’s more where that came from so if anyone has any suggestions for debugging a language where the variables seem to come from nowhere, or can remember how to work with PHP with register_globals turned on, I’d be grateful :)