PHP Questions

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

PHP Question: Named Variables

Question

What does the following code snipped print?

$a = 5;
$b = 'a';
print $$b;

PHP Question: Octal Values

Question

If I assign and print a value like this:

$a = 012;
print $a;

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

PHP Question: Include And Require Files

Question

What's the difference between include() and require()?

PHP Question: Increment By One

Question

What will the following snippet print, and why?

$count = 0;
print $count++;

PHP Question: Printing A Boolean Value

Question

What will the following code print, and why?

echo TRUE;

PHP Question: Scope Resolution

Question

What is printed after the following code has been run?

function calc() {
    $a = 1000;
    return $a;
}

$a = 1;
calc();
print $a;

 

PHP Questions

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.