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 …

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 :)

UK PHP Conference: The Roundup

As promised, here’s a more in-depth update on our trip to the PHP London Conference last week. I’m sure there are others who will write more fluently and accurately about the talks, but here’s what I brought home from it.

Cal Evans: My First Mashup

Cal is a personal hero of mine, as I said earlier, so I was really looking forward to his talk. He did a simple mashup of two APIs which tracked a UPS package to its destination on a Google Map. He used APIs from both companies and had a working demo to show.

Although he showed JSON and XML data formats, he mostly seemed to be using XML and had some good things to say about the SimpleXML functions now in PHP 5. For making the API calls he used script.aculo.us.

From the talk I came away with a clear picture of how a mashup goes together and a sense of confidence that when a project comes along for me that needs it I’ll just dive right in. I saw the whole API idea in action when writing PlayTAG for the PHP Throwdown. Cal also pointed us at http://www.programmableweb.com/ which looks like a good resource.

Simon Laws: Web Services

Simon was talking about a project he and his colleagues have been working on to create consumable services, which followed on nicely from Cal’s talk. The project is a PECL module and their page is at www.osoa.org, its good to see business contributing so nicely to the community.

The idea of the project is that you can write some class-based functionality and then expose that to be called as a service by some external script. It was interesting and the talk was well-prepared with demonstrations and code snippets all at different points along the development that Simon walked us through. My personal favourte moment was him typing “phuk” rather than “phpuk” into a sample input … perhaps that just my twisted sense of humour. One thing that really impressed me was that they had spent a lot of consideration about making different formats available and providing various bindings for accessing the services. Some of that information about what’s available for what type of service is held in phpDocumentor-style comments at the moment but it could easily be generated as a static companion file or something further along the line.

Best of all was getting to catch up with Simon and his colleague Caroline (a PHP Women friend of mine) at the event after the conference and ask them a bit more about their job. They were both interesting and friendly people.

Kevlin Henney: Objects of Desire

Kevlin was very brave to come and speak as he’s not a PHP-er himself most of the time (or so he claimed). He was talking about the PHP implementation of Object Oriented Programming in comparison with other languages including Java and C++. His talk was based around a series of questions and he was a very entertaining speaker.

His perspective of coming from a wider background than just the single language was very interesting and I did feel that it gave a much more balanced perspective on the topic. The talk was based on answering a series of questions and this worked very well. In particular he was talking about unintended properties of objects and illustrated this by showing that his bottle of cough mixture had the property “throwable”, as it was quite small and aerodynamic … I did warn you he was entertaining :)

Rasmus Lerdorf: Fast and Rich Web Applications with PHP 5

Rasmus Lerdorf is the godfather of PHP and a nice guy. I’ve heard him on podcasts, own some of his many books, and have even corresponded on forums with him but not seen him in the flesh before so this was interesting. He was talking about PHP5 and then went on to answer quite a few questions which was very interesting. At the beginning there was a problem with the wireless in the venue and he raised a smile around the room by putting up a slide which showed photographs of:

  • a ship in the Mediterranean
  • a field in India
  • a mountain in Cambodia

And then explained that these are all places where he has given talks and wireless internet access had been arranged … we were in Central London!!

Rasmus talked about the movement to PHP5 and adopter rates and barriers. He recommended using the Filter functionality in PHP for all input variables and gave some good examples. His other recommendations included making use of the static keyword where appropriate to prevent unexpected usage or extension of methods, and also use of the -l switch for checking PHP4 code prior to deployment for PHP5.

Conclusion

For an even costing £50 and organised by volunteers it was an excellent day! There was coffee available at every turn and lunch was provided, they certainly knew how to take care of geeks. Attending the pre- and post-event socials definitely led us to get more out of the whole experience and meet some very interesting people. It was well worth the effort and I’d certainly recommend this to anyone interested in PHP for next year.

UK PHP Conference: The Highlights

I’ve been away for a couple of days at the UK PHP Conference in London. Due to the unique way that train ticket prices work here, it was wildly cheaper to travel a day either side of the day we actually wanted to be in London for which allowed us to take in some sights and socialise with some other PHP-ers.

I’ll post more about the conference itself but for now I’d like to leave you with the highlights.

  • Hearing Rasmus Lerdorf speak … he was interesting and entertaining and managed to out-geek everyone there all in one go.
  • Getting to say hi to Rasmus later on (I was probably quite star-struck but never mind! I do own a few of his books so I’m allowed to idolise slightly)
  • Getting to say hi to Cal Evans, editor of Dev Zone and all-round good guy. He helped phpwomen.org in its infancy. In addition Cal is now my hero as he gave me a pack of the PHP Playing Cards I have coveted for so long! He just had a few sets in his hand after his talk and gave them to bystanders, talk about the right place at the right time.
  • Meeting a phpwomen.org friend in real life for the first time :)

CMS Promiscuity

This site is run by textpattern, I’ve used it a few times and I love it. In addition you may have read about my recent encounters with Joomla! .

This week I’m trying out Serendipity for another site and its quite a change. For a start I haven’t read a lot about it although there are a few places that I’ve notice it used (on Sara’s blog for example) and wondered about it. It turns out its templates use Smarty which is good for us as quite a few of our recent projects have (both woollyblanket, for its user management bit, and our recent experience creating playTAG.

First Impressions

Well the installation was a dream, which I kind of expected, but its great to see all the same and a nod to the team for that. Getting started with the admin side of things wasn’t too hard either – you install a plugin called “Spartacus” and then you are able to download and install any plugins and themes from their central respository. Its very convenient and perfect if you only have FTP access or just don’t want to mess about moving files from one place to another.

Getting a site running

The admin interface is quite simple – you add content items into categories in a way that will be familiar from other comparable CMS products. Getting some navigation to happen needed a selection of plugins but installing each one is pretty painless. The configuration screen shows the “sidebar” plugins in the location that they will appear followed by the “event” plugins which are the ones that modify the functionality.

What Next?

Well, I’m not posting the URL of the project I’m using Serendipity for just yet, because it’s not ready. I hope the suspense of wiating to find out what the site was and what I did to Serendipity in the process won’t be too much!

PHPThrowdown Coding Contest

This weekend, Kevin (boyfriend) and I took part in the first PHPThrowdown event. While its true that programming contests aren’t new, I haven’t seen one that seemed relevant to me for a while and they do take a lot of organisation – so kudos to the organisers including fellow PHPWomen.org -er Elizabeth Naramore.

The categories were:

  1. php-gtk
  2. inventory management (either home, work.. etc)
  3. games
  4. anything goes

We don’t know much about php-gtk and we were certainly not going to go there in the games category as its likely to be very popular, so we thought we’d think up something on the home/office line and ideas of calendars and to-do lists got kicked about. The problem with something you are going to write in 24 hours and which is going to be tested by people standalone is that a) you need to get content from somewhere or they won’t stay long and b) it has to be relatively simple or you’ll have a lot of buggy functionality and not much else.

So it was that playTAG was born. It turns out that it isn’t an especially new idea, disappointingly, and there are lots of games which work by challenging you to traverse from A to B using related tags. An example is the Wikington Crescent game on Wikipedia. We drew our page layout, data structures and who-does-what lists up and then we began the 24 hour marathon.

The Marathon Begins

So its wasn’t much of a marathon. I went to a party a couple of hours after the contest started and that was it from me for the first 12 hours!! Kevin did much better and managed almost 8 hours before he went to bed. I got up early (ish) and looked at his notes from the night before … we had to check in every six hours so I swiftly did that and then settled down to write my bit. We were both on stream for the final 8 hours and made something which actually works.

Our strategy all along was for me to deal with the admin, making sure we had the right check-ins, writing the README file, and packing the thing. Kevin kept going, ironing out problems and also adding the features as it became clear what we had time for.

The final result

Well the judging starts now and will go on for a while. I’m sure we won’t be hearing anything more about it but since I’m so proud of our day’s work I’ve put a version online to show you! Here it is: playTAG – enjoy :)

Why PHP isn’t so bad

I love PHP. I’ve worked with a fair number of languages and I have to say that I absolutely love PHP. I love its cleanliness, its elegance, and its fabulours online documentation and community support.

I come across a lot of people in various walks of life who rubbish the language because of various perceived (usually historical) weaknesses. So when I saw this article from DevZone I felt I had to post and say how much I agree with it. I also think that the PHP community might benefit from a little more self-promotion once in a while … but it seems that everyone is rather too busy “solving the web problem” (the original aim of PHP) to worry about little things like that :)

Joomla! Brief And Pretty URLs

Well the website for my netball club is definitely going ahead, They are even more up for it than I imagined! So you can find the new site at www.shipleynetball.org.uk and hopefully it will actually get some content soon.

Installing Joomla!

I installed a new copy of Jooma! which was just as easy the second time as it was the first – you literally sit down to install it and before you remember you forgot about your coffee, its done and you’re already fiddling with the administration tool. This time I installed some extras.

EventList

I can’t say enough about how much I like the eventlist component from schlu.net. In addition to the date management bit which I tried out before, I’ve also installed the calendar module that is also available. I know its very alpha but I haven’t managed to break it yet and its exactly what this module needed! Also it makes sense for the users on the netball site to click on a particular saturday and see all the fixtures by day so that’s very good.

Another thing I must mention again about this component is the locations functionality. We play at one of five venues and you have to input the venues before you input the events but then once the address information, directions and whatever have been input they get associated with the fixture automatically … and its got a google maps link too :)

OpenSEF

Pretty URLs are something I feel quite strongly about. They’re strong and human-memorable which I think counts for a lot. I understand they’re also really good for search engines although I’m not an expert and I am under the impression that search engines kind of read your content these days. Well this was a complete faff from start to finish. It took me literally two hours from start to finish and that was only because I gave up, set the thing up manually, and sat down to write this before bed. Here are the steps I think I probably needed to follow, in the order it happened.

  1. Firstly, you need apache mod_rewrite and all the forums will tell you to test this first. Which is a good start.
  2. Turn on the Joomla! search engine friendly URLs (under Site -> Global Configuration -> SEO -> Search Engine Friendly URLS) and take a few moments to check that those are working. I have no idea what a search engine would find friendly about those URLS, they had commas in which I always find unnatural but never mind!
  3. Now try to move forward with the OpenSEF component. Basically you install it, and then you keep reading the tutorial because there’s some faffing about with the .htaccess file. Gotcha: The old Joomla! search engine friendly URLs need to be enabled as well – I turned them off when I commented out all the stuff relating to them in the .htaccess file without realising I wasn’t supposed to be doing that!
  4. Once its working, the pretty URLs get generated when you click on the links, so it will show the old link and then when you follow it it generates the pretty one, redirects you, and then uses it forever after. It is possible to input links manually in the administration part. I found that one of my plugins just would not get linked properly, it was listed under Components in the Admin part of OpenSEF, and I enabled that, and the pretty url resolved to the component if typed in directly, but it just wouldn’t update itself. As I say, I gave up and entered it manually … and now I’m never touching my links again! I think stuff like item and category links are going to work pretty well though and I think that’s really important for when we add additional content to the site.

Anyway I still like Joomla! and I think its going to be a nice simple interface for the people who are going to be writing articles for the site so I’m still quite pleased with it, if temporarily exasperated! If anyone knows what I was missing then suggestions are gratefully received.

London PHP Conference

Its all sorted and we’re booked onto the London PHP Conference in February. Its a bit of a geeky thing to do as a couple I suppose but I’m really looking forward to it. There are some speakers that I will be positively star-struck to see in the flesh (Cal Evans and Rasmus Lerdorf) and some people that I’m really looking forward to meeting in person that I have had contact with online.

Due to the exciting way that train fares work here in the UK, its much cheaper to travel to London on Thursday evening1, stay both Thursday and Friday night in a hotel in central London and then travel back on Saturday afternoon. To be fair the journey back is cross-country and takes 4 hours but I upgraded the tickets to first-class for £3 and we won’t be changing trains so I’m sure it will be fine.

I’m really looking forward to hearing the talks and meeting the people at the conference, I’ve never been to anything like it before and I can’t wait! Also two nights in central London with Kevin can’t be a bad thing :)

1 To put this in perspective, its costing us £9.50 to travel on Thursday night and the walk-on Single Fare is £273. It really pays to be organised.

Dating Joomla!

Well its early days in our relationship but so far, Joomla! and I are getting along just fine. Since I installed it I’ve had a proper fiddle with most of the bits and pieces (mostly turning things off actually!!) and now its looking much better.

Since I’ll want to introduce fixtures, I’ve used a calendar extension called EventList from schlu.net and its fabulous. It took me ages to get the idea that to change how a category displays its items, you edit the menu item that points to it. It still seems like a bit of a funny concept (what if you link to it from somewhere else?) but it really works now I’ve figured it out. I used this to stop the date and author being displayed in the “Venues” section, since they don’t mean a lot. To remove the same information from the individual articles I edited each article individually.

I’ve also changed templates, there are loads available to download but I was struggling a bit with ones I didn’t like or didn’t know how to change. In the end I chose the “sporticus” one from www.rockettheme.com, it was easy to change the colour and I made some other changes to it as well.

At one point I got quite stressed with the layout of news articles on the front page, one or two was fine, but three did a funny layout with one at the top and the next two next to each other. Once again its the menu item property, I changed the number of columns to put all the articles in line with one another and it looks great!

The other thing I must mention is the community, I’ve registered for the forums but so far have been able to find things I needed just by searching the threads. The tone of the forums is much nicer than I’ve seen elsewhere and most of the Joomla! gang seem keen to spread the word. I must also give a special mention to my phpwomen friend and personal Joomla! consultant, Amy who has been very helpful and even answered questions before I ask them :)