PHP Questions

PHP questions suitable for use in interviews or just for fun.

PHP Question: Octal Values

15th April 2011

Question

If I assign and print a value like this:

  1. $a = 012;
  2. print $a;

I get back a value of '10', why?

PHP Question: Scope Resolution

6th April 2011

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 Questions

6th April 2011

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.