PHP Test

This is a preliminary test for PHP Developer's looking to join the team at Edmonds Commerce.

This test is to gauge your PHP level. It is designed to be done in your head without use of any other tools.

Please stick to the spirit of the test and have a go at it. If you do feel you need to use other tools to answer these questions then it probably means you aren't really up to the level we need at the moment.

We would expect completing this test to take no longer than 10 minutes, usually less than 5.

Warning: There is no form validation, part of this test is your ability to fill out a web form or complete other basic tasks without mistakes.

YOUR DETAILS Name:
Email:
QUESTION 1 Which values should be assigned to the variables $a, $b and $c in order for the following script to display the string Hello, World!?
function helloWorld($a,$b,$c){
    if ($a) {
        if ($b && !$c) {
            return "Goodbye Cruel World!";
        } else if (!$b && !$c) {
            return "Nothing here";
        }
    } else {
        if (!$b) {
            if (!$a && (!$b && $c)) {
                return "Hello, World!";
            } else {
                return "Goodbye World!";
            }
        } else {
            return "Not quite.";
        }
    }
}
$a='?';
$b='?';
$c='?';
echo helloWorld($a,$b,$c);
                



QUESTION 2

Array values are keyed by values (called indexed arrays) or using values (called associative arrays)

QUESTION 3
	$s1='Edmonds';
	$s2='Commerce';
                

Which of the following will combine strings $s1 and $s2 into a single string "Edmonds Commerce"?

A. $s1 + $s2
B. "{$s1} {$s2}"
C. $s1.$s2
D. implode('', array($s1,$s2))
E. All of the above combine the strings
                





QUESTION 4
$s = '12345';
$s[$s[1]] = '2';
$result = $s;
                

What is the value of $result

QUESTION 5

What is the missing function used to get a line as an array from a valid CSV file?

$fp = fopen('file.csv','r');
while($csvrow = _what_function_($fp)){
    $csvrow; //is an array of values from the csv line
}
                
QUESTION 6

Often, SQL queries are constructed based on data taken from the user (for instance, a search engine). Which of the following activities can help prevent security breaches?




QUESTION 7

What is the output of the following pieces of code?

class animal {
    public $name;
    protected $sound = '';
	/**
	 * Set Name
	 * @param string $name
	 */
    protected function setName($name){
        $this->name = $name;
    }

	/**
	 * Speak - get the string that they speak
	 * @return string
	 */
    public function speak(){
        return "No Animal Selected!";
    }

}

class dog extends animal {

	/**
	 * Set the name and the noise that is made
	 * @param string $name
	 * @param string $sound
	 */
    public function __construct($name, $sound='woof'){
		$this->sound = $sound;
        $this->setName($name);
    }

	/**
	 * Speak - get the string that they speak
	 * @return string
	 */
    public function speak(){
        return "{$this->sound} {$this->sound}";
    }

}

class cat extends dog {

	private $motivationThreshold=20;

    /**
	 * Set the name of the cat
	 * @param string $name
	 */
	public function __construct($name){
        $sound='Meeooww';
		parent::__construct($name, $sound);
    }

    /**
	 * the noise that they make
	 * @return string
	 */
	public function speak(){
        return $this->sound;
    }

    /**
	 * Are they motivated enough to walk
	 * @param int $motivation
	 * @return string
	 */
	public function walk($motivation){
		if($motivation > $this->motivationThreshold) {
			return "There must be food, I'm walking";
		} else {
			return "I'm a cat leave me alone";
		}
	}

}



class human extends cat {

	/**
	 * Magic __get Method
	 * return 0 for any properties that don't exist in this scope
	 * @param string $property
	 * @return int 0
	 */
	public function __get($property){
		return 0;
	}

    /**
	 * Set the name
	 * @param string $name
	 */
	public function __construct($name){
        $this->setName($name);
    }

	/**
	 * Are they motivated enough to walk
	 * @param int $motivation
	 * @return string
	 */
	public function walk($motivation){
		if($motivation > $this->motivationThreshold) {
			return "I'm highly motivated";
		} else {
			return "I must be ill";
		}
	}

    /**
	 * Say hello
	 * @return string
	 */
	public function speak(){
        return "Hello, My Name is " . $this->name;
    }

}

$animal = new animal();
$dog = new dog('rover', 'woof');
$cat = new cat('garfield');
$human = new human('fred');

                
7.A
echo $animal->speak()
                
7.B
echo $dog->speak()
                
7.C
echo $cat->walk(15)
                
7.D
echo $human->speak() . ' ' . $human->walk(5);
                

To prove you are human:

What farm animal says "Mooo"?