Saturday, May 30, 2009

Elusive PHP syntax errors - a strange fix.

I found a variety of syntax errors when debugging a PHP script lately. Since the PHP parser isn't the clearest when it comes to debugging (and these were terribly elusive) here are are some methods that I found to solve the problem.

The line numbers associated with the errors were no help at all - the error just wasn't found on line 1. And then when the line number changed, it was not found on line 34 either.

These errors included both "Unexpected $end" and "Unexpected [T_variable]" errors.

As this script was a mixture of PHP and HTML, the page was fairly long and daunting. I looked for missing brackets, tick marks, quotes, and reserved words.

I reviewed every line of code for semicolons and matching parentheses and brackets. No luck. I tweaked variable names in the lines above where the reported error was. Still no luck. Since from what I've read about debugging PHP syntax errors said the line number is 'around' or typically a line or two above the reported line number, I sat there staring at each place the bad formatting of code should have been. Nothing!

One method I came up with that I didn't find online was to separate the script into chunks. As it was a syntax error (how things were formatted), I simply segmented the script as I could, added a little HTML 'hello world' to the page (to make sure I wasn't just seeing the PHP white screen of death), and previewed different sections of the code up on the server.

I copied each logical segment of code to a new file and ran it. No errors. Eventually I copied the entire contents. Still no error in the new file. At that point I was about to pop in frustration.

I was methodical and the fact that the errors changed when I tweaked code in the original file (which seemed formatted correctly to me to begin with), was annoying to say the least.

It could be that there was a small part of the file which was corrupted while I had it open in notepad++ or maybe up on the server. Strangely enough, copying the entire contents of the script to a new file and then saving it over the old one did the trick.

It ran beautifully after that.

So, a few PHP syntax debugging tips for myself to remember in the future. Especially if they become elusive and persistent like this last time.

1.) Use something like Notepad++ to help highlight matching brackets, reserved words, quotes, and semicolons.
2.) See the PHP Syntax error wiki.
3.) If it's a long script and the syntax errors jump to different line numbers after tweaks, first copy the entire contents to another file then take segments of the code and paste it into a new file.

Sunday, May 03, 2009

Quick Searches. Possibly the end of my temporary keyword mania.

When I started this blog a week or so ago, I didn't think the first few would be dedicated to Firefox features but I have to mention Quick Searches before letting go of the keywords tips.

I was talking to Matt (Drupal enthusiast extraordinaire) about how I'd found what I thought was a more convenient way to search. I was both surprised and happy to be wrong again when he explained searching Google was as easy as creating a new tab, then pressing the tab key to get to the Google search native to Firefox.

Pressing control-t to open a new tab, then hit tab. You're ready to search Google.

Neat. Good on'ya Matt. I was using this religiously.

Then complimentary to my keywords kick (see last blog), I started reading into Firefox's Quick Searches.

My biggest sigh of relief has been using the Quick Searches for SourceForge.net. The intro page loads too slowly. Now all I do is hit control-L (or control-T if I want it in a new tab) to get to the address bar and type: sf image map

.... and I get a list of matches for image map software from SoureForge's projects. Even neater.

The sweet part about it is that it works for any site with search. Simply right-click in any single search field and you are prompted to create the shortcut. Enter your keyword (a short one like 'g'!) and save your bookmark.

I save mine to my own Quick Searches folder. From what I've read it's supposed to be there already, but I must have deleted mine thinking it was nothing but clutter.

Lifehacker's article on using Firefox Quick Searches is better than what I would put together this evening. I highly recommend checking it out if you are interested in the keyword shortcuts.

The pages I need fastest.

I tried using FastDial for FireFox but it didn't do everything for me that I needed.

Having each of my most used pages ready to click whenever I opened a new tab was hip but unfortunately it wasn't fast enough for me. An intuitive-type person might like FastDial. You're presented with boxes where small representations or icons are displayed for you to click on.

That's too many steps for me. When I'm looking for a link to page when I already know what that page is, I don't want to look through eight or ten images to figure out which one it is.

I took advantage of keywords instead. They are only available in Firefox. Internet Explorer allows you to assign shortcut keys, but not keywords.

A few links to help get you acquainted:
Firefox keywords
Lifehacker article on Firefox keywords - with some good links in the article.

What I've set up at my daytime job is a series of keywords to the pages that I use most frequently. Since there are a lot of different tasks I need to perform when an incoming call comes in or a form is submitted, I need to get to a variety of different web pages without too much thinking.

What I've done is take the most common pages and bookmarked them, while adding a keyword - specifically a keyword associated with the task.

When someone calls in to change their payment type on their account, I type 'pay' in the address bar (or hit control-l to get to the address bar and then type 'pay' and then hit enter).

I do this for a few others as well.
whois - Network Solution's whois check
signup - account creation form internal to my company
(webservername) - direct access to an web-admin interface of a server.
mon - a monitoring utility
st - staff pages internal to our company
kb - the company knowledge base
modems - a link directly the reference for DSL modems that we use at work

I'd imagine this would be especially useful with frequently used Google Documents - and I may be making more web pages specifically with this use in mind.

At home I've been thinking a few would be helpful
fb - facebook.com
bank - self explanatory, no?
ms - myspace
tw - twitter
bl - my blogger account
e - my webmail account.

I might even go further and open multiple tabs with a single keyword if I find the need for it. That might come in handy for web development projects.

Saturday, May 02, 2009

A fresh start for my tech blog.

As I've found a new focus for the site, I'm going to be sharing the answers to the questions that have befuddled me during the course of my knowledge and technology work.

All of the old blog posts have been deleted (they were largely useless anyway), and I'll be posting as regularly as I can with the answers I come up with about working in technical support and knowledge-work.

I define knowledge work for myself basically as managing my incoming responsibilities and how I handle them until completion. Being headstrong, there many frustrations in the office environment that I run into.

This is the best place I can think of to share the answers I come up with to combat or work around those frustrations.

Also, if you're someone who works with any sort of technology I'm sure you run into the problem of unresolved questions. No amount of training can completely prepare you for what goals are going to be thrown at you as a worker.

Meeting and resolving the challenges that arise in the office, obstacles in web development, and combating my own bad habits with office-work are primarily the focus of this blog.

If you're in a similar boat, I hope you find these things useful (including the many forehead smacks about the painfully-obvious). Those aren't usually fun for me, but they might be entertaining for you.