PHP

Removing extra whitespaces on bunch of PHP files using Ack-grep and Emacs

As a follow up to my own post on Indentations: Tabs vs. Spaces, I wanted to cleanup a number of files that contained a lot of extra and useless whitespaces that were getting on my nerves.

I did not want to spend too much time on this so, here is what I did.

First, here is what I have in my .emacs files that is needed for this to work:

(require 'whitespace)
(setq-default global-whitespace-mode t)
(setq-default whitespace-modes (quote (php-mode c-mode)))

Install pear without network (no internet access/offline)

I was faced with a problem. I wanted to use drush on a server that had no internet access. Well, I could connect to it but it could not (for security reasons) connect to the outside world.

Drush requires PEAR's Console_Table and that in turns requires PEAR, obviously.

First I downloaded all the PEAR packages that I needed from my desktop and then I uploaded them to the server using SFTP. I could also have used a USB key if I had physical access to the server but that as not my case.

The files that I downloaded were the .tgz files that I found here:

array_unique returns NULL

I am dealing with legacy code written by another team and someone asked me why his images were not showing up...

Took me an hour to dig that one out.

Simply because the optional second parameter to array_unique() was only added in php 5.2.9 and we were using 5.2.4 ... Therefore it was generating an error that was hidden (because of error_reporting) and returning null.

I removed the second parameter and VOILA!

Too bad the sysadmin does not allow us to upgrade PHP. :)

Indentation: Tabs vs. Spaces

This is one of these archaic question.

Short answer: Spaces, and only spaces.

Long answer:

Origins
The tab key on the keyboard seem to have first been introduced with typewriters and then with computers. The original idea was not about indenting complex code structure. A long time ago, some people started to use tabs for indentation because of the disk space it was saving.

Concept

Reading book: Zend Framework 1.8 Web Application Development

I am currently working on a PHP project which involves creating web services with Zend Framework.
I started reading the book "Zend Framework 1.8 Web Application Development" and I plan on doing a review soon.

Selenium and popups.

I wanted to write a selenium test script to validate calculation done in a page to make sure they match those of another page. I used the store* functions to grab the values from the source. My problem was that the second page was actually a popup.

There have been some reported problems with selectWindow and selectPopup and waitForPopup functions. They are not always working with Firefox 3.x. They were not working for me.

So I thought that maybe I could have the page NOT popup when it's being accessed by selenium. That way I will not have to use these broken functions.

Detecting mod_rewrite using PHP

The following post is about a solution to the problem of detecting if mod_rewrite is enabled or not. I worked on a project where CS-CART was used and after it was installed, it was complaining that the mod_rewrite module was not installed. I knew that mod_rewrite was installed so I looked at the code. The code that was detecting if mod_rewrite was enabled was assuming the DNS for the domain was working fine. It was doing an HTTP request. This means that if we installed the store in a temporary environment where the hostname is fake (put in the HOSTS file for example) then it would think mod_rewrite is NOT installed or enabled.

I think I came up with a better way and here it is. I submitted it to the CS-CART staff, we'll see if they like it.

Watching a file on disk

Paul Reinheimer wrote an article on a bug he was trying to solve.

He wrote:

Something I would love to have: An application that watched a file on disk, reporting all versions of the file over time. tail -f wont work as the file is a single line long, the line is changed but no new lines are added. I'm aware of similar tools for windows, none for mac/linux.

If you want to watch the last lines of a file to see when it changes, try this in linux:

 

Under used resources - Get all the answers

In any development shop with more than one developer, there is always at least one developer that is THE reference for the project/platform/framework/cms that most developers go to with questions.

Let's face it, developers are lazy. I mean very lazy. I am lazy! So we look for the easy way. The path with the least resistance. Sometimes (maybe most of the times) that is going to see that senior developer and asking him questions.

I am profiling too!

Earlier this year (march 2007) I went to the PHP Quebec Conference in Montreal where I met Rasmus Lerdorf. He gave a very interesting presentation where he talked about various things, including something called calgrin, xdebug and cachegrind. It seemed very interesting but I did not have the opportunity to try it. Until recently that is, now that my project is in beta in terms of features and that we need to tune it to increase performance. I saw this post and it reminded me of these tools.

Syndicate content