PHP Logo

PHP Question: Scope Resolution

6th April 2011 - 1 minute read time

Question

What is printed after the following code has been run?

  1. function calc() {
  2. $a = 1000;
  3. return $a;
  4. }
  5.  
  6. $a = 1;
  7. calc();
  8. print $a;

 

PHP Logo

PHP Questions

6th April 2011 - 2 minutes read time

As part of a new series of posts I will be creating a set of PHP questions suitable for use in interviews or just for fun. They will range from the very easy to very difficult but are all designed to test one or two specific parts of the PHP language. The idea is not to test for knowledge of the order of PHP function parameters (which I often have to look up), but more to test if the candidate knows how the language works. It is also quite a good mechanism to post about some of the fundamentals of the PHP language.

PHP Logo

Revisiting filter_var() and FILTER_VALIDATE_URL

1st April 2011 - 6 minutes read time

Quite a while ago I looked at using the filter_var() function to validate URL's using the FILTER_VALIDATE_URL flag and someone pointed out recently that this function has not only changed since the initial release, but that a number of flags can be added to change the way that this function works. Here are the flags available.

Drupal Logo

Overriding Drupal 6 Automatic Select Element Validation

29th March 2011 - 9 minutes read time

Whilst creating a large and complex form in Drupal 6 recently I hit upon a problem that took me a couple of hours to solve so I am posting the solution here in case anyone else gets similarly stuck. I am also writing this down so that I can remember the strategy in case I have to do the same thing again.

What I was doing was creating an event booking form. The form allowed users to select from a number of times slots in a select list, but each time had a limited number of bookings. When the user submitted the form and all allocated slots for their selected time were fully booked they were shown a message asking them to select a different time slot. The original time was removed from the select list so that the user didn't try to select it again. This was fine and it all worked as expected but when this happened I also got the following error message from Drupal.

Drupal Logo

Drupal 6 Views Templates

22nd March 2011 - 14 minutes read time

Rewriting the output of a Drupal view isn't always necessary, but figuring out what to do with the available templates can very useful. It is, however, also a bit of a stumbling block from time to time, especially for newcommers. After you have created your view you will have a number of filters to restrict your data, and a set of fields which are printed by Views using a set of templates. How these templates are used depends on what sort of view data you use and style you select, but there will be three standard templates that are always used in views. These templates are display, style and row and can be treated like any other Drupal template in that you can override them with more specific filenames.

#! code Logo

Ideas Of March

17th March 2011 - 10 minutes read time

This week I was pointed, somewhat ironically through Twitter, to a blog post from Chris Shiflett about how we need a blogging revival. Which is something I quite agree with as although Twitter is great for a sense of community, it is impossible to impart good technical knowledge and/or experience through 120 characters.

Blogs are a fantastic resource. I have lost count of the times that I have been stuck on a problem and after a quick bit of searching I have found a blog post from someone who had exactly the same problem, but managed to find a solution to it. I have quite a few people who have done the same thing with #! code and have posted comments on how I have helped them out, which I find really rewarding.

Drupal Logo

Drupal 6: List Selection Zero Value Fix

7th March 2011 - 3 minutes read time

I discovered a little issue recently with the Profile module in Drupal 6 and after finding the solution I thought I would post it here in case it helps anyone else.

The problem occurs when using the list selection form item in a specific way. This form item works find for just about every situation, except one special case. Lets assume that you wanted to ask a user a question which requires a number between zero and four; you enter the following into the selection options box.

PHP Logo

PHP Unconference Europe 2011: Part 2

3rd March 2011 - 27 minutes read time

Sunday

Due to the crappy train service from my home town I had to drive into Manchester on Sunday, but made it in good time to have a coffee before we went to vote on the talks. Some people had a heavy night drinking the night before and therefore didn't make it in the morning (or at all). Some has also opted to only attend the Saturday and so there were a few faces missing, but there were still plenty of people there.

PHP Logo

PHP Unconference Europe 2011: Part 1

27th February 2011 - 20 minutes read time

This weekend saw the PHP Unconference Europe 2011 event in Manchester. The organisers were hoping that the rain would hold off for the weekend, and being true to form Manchester was wet and cold. Being an unconference the talks and discussions are mainly casual and dependent on what everyone decided to see on the day. The event ran across Saturday and Sunday with different talks on each day.

Saturday

Picture taken by Lorna Mitchell.