Passive Aggressive

I had a pretty rough day last Wednesday. I tried to code in a way I normally do with concepts I thought were the same across most languages but it didn’t work. PHP does not have pointers. Their concept of ‘references’ is, in my opinion, flawed. A reference is basically a pointer to the variable itself. In C we define this as int**. The crux of this is that if you change the original variable the other variable changes too. Make sense? Not in your life. This is a situation where a statement has unexpected side-effects. A statement talking about x can actually be changing y and z as well. This coupled with the fact that php does no scoping within a function means you have to be very careful when dealing with references.

So I now understand this concept, and in a few parts of the otherwise elegant and understandable system I use the function unlink before setting the variable to something else, even if this is at the end of a loop because the start of the loop sets it again. So this was annoyance one.

Alex had noticed that the log files on the server were getting astronomically large. We are talking 350MB of text. This is a significant amount for a hosted website.

So I was criticising Alex’s code, not something that I normally do but I was annoyed and taking it out on others (sorry!). I had a go at rewriting a function that he had hacked to add some extra functionality. I managed to get it down to a few lines. Alex pointed out that what I was doing was incorrect. My rebuttal was that PHP would tell me if I was doing something wrong. Turns out that this is wrong. Whenever possible expect PHP to be configured and written in a way that almost encourages sloppy code. By default PHP, and the package xampp that we are using for development, have notices turned off. This is a problem, but not a biggy. What is a problem is that code that normally stops a compiler of a decent language only generates a notice in PHP. How sad. The combination of notices not showing and PHP only generating notices meant that errors in my code were getting through to a live site.

Upon turning on all errors, warnings and notices we were bathed in a large list of notices. The reason for these was in part due to PHP’s lack of elegant syntax and non-object way of doing things. So the code I have been writing for 2 months was incorrect. This was quite a blow to me as I take pride in writing proper, elegant code. I spent around an hour fixing all the errors.

Media Temple, the hosting we use, has notices logging by default so this was the cause of our overly large logs. This logging is arguable for a production server, but I think it is a great thing because it allowed me to find something I was doing wrong.

0 Responses to “Passive Aggressive”


  1. No Comments

Leave a Reply

You must login to post a comment.