Resolving PHP errors without knowing PHP

Paying more attention to my blog this Semester (obviously) I noticed there was a very simple, but annoying error when viewing a single post: the headline, content and comments were all listed twice on the one page.

As it’s been five (5) years since I last looked at the code, which even then was a “cut, paste and hope” effort – code from WordPress placed on the site – I couldn’t even remember whether this error had crept in somehow or had been there since launch. So fixing it was going to be no easy task.

The proposed solution: trial and error. I went through different sections of the PHP statements, cutting out different chunks each time and testing to see if I could isolate the code that was causing the problem. This was actually inconclusive – after a dozen combinations, hiding bits and pieces, I was still getting the duplicate.

So as a different method, I compared to a different section, the home page, which includes the post with less details. It was here I found the following …

BEFORE the content:

<? php static $ctr = 0; ? >

AFTER the content:

< ? php $ctr++; } ? >

Funnily enough, I still don’t know what the syntax means for these statements, but happily I don’t need to: I know that they’ve fixed the problem. The moral of the story being – it’s about the result, however you manage to get there!

2 thoughts on “Resolving PHP errors without knowing PHP

  • August 30, 2008 at 12:15 am
    Permalink

    Hey Ian, glad you could fix that bug! Sorry I said I’d help you the other day and then I forgot, but it’s probably best that you fixed it yourself 😉
    By the way, the code you’re trying to show on your blog spot doesn’t seem to display properly. Maybe try surrounding them by ‘pre’ tags: http://www.w3schools.com/TAGS/tag_pre.asp

    You might also need to escape the code, so it is not rendered as HTML itself. For examples:
    http://www.html-reference.com/Escape.htm
    http://www.theukwebdesigncompany.com/articles/entity-escape-characters.php

  • August 31, 2008 at 2:00 pm
    Permalink

    Hey Julien,

    Ironic that I post about annoying little bugs and manage to find another one eh? 😉

    Thanks for the heads up on ‘pre’ – surprised I haven’t seen that before. I think my WordPress version is getting a bit behind, I installed it years ago and have not touched it since – there’s actually a security flaw I’ve not been able to fix which is annoying (cloaking – grrr) … solution will end up being a complete replacement I think. Maybe after Semester!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.