1.What happens when you run the following MySQL Query ?
CREATE TABLE PRIMARY (ID int);
Syntax Error - PRIMARY is reserved in MySQL and should be quoted to be used as a table name
Syntax Error - PRIMARY is reserved in MySQL and can not be used as a table name
A table called PRIMARY containing a column called ID is created
2.What is the output of the following script ?
<?php function generate() { for ($i = 1; $i <= 3; $i++) yield $i; } $generator = generate(); if(is_array($generator)) echo "Is Array"; elseif(is_object($generator)) echo "Is Object"; else echo "Is none of the above"; ?>
Is Array
Is Object
Is none of the above
3.What happens when the code below is executed ?
<?php class foo { private $variable; function __construct() { $this->variable = 1; } function __get($name) { return $this->$name; } } $a = new foo; echo $a->variable; ?>
The script outputs 1
Fatal error: Cannot access private property foo::$variable
The script outputs 0
4.Considering the code below ...
<?php class AppException extends Exception { function __toString() { return "Your code has just thrown an exception: {$this->message}\n"; } } class Students { public $first_name; public $last_name; public function __construct($first_name, $last_name) { if(empty($first_name)) { throw new AppException('First Name is required', 1); } if(empty($last_name)) { throw new AppException('Last Name is required', 2); } } } try { new Students('', ''); } catch (Exception $e) { echo $e; }
... which of these statements are correct ?
The catch (Exception $e) statement is wrong because it accepts an instance of the Exception class as the parameter. It should use an instance of the AppException class instead.
catch (Exception $e)
The __toString() method can't be overwritten in a child class because the methods in the Exception class are all final but for the constructor
__toString()
Exception
The magic __toString() method will be invoked automatically when the code enters the catch() statement and the custom exception message will be printed
catch()
5.Assuming that the code below is in a file named "test.php" and that PHP has full rights over the file, what happens if the file is executed from the command line without any arguments ?
exec("rm -f " . dirname(__FILE__) . "/" . $argv[0]);
The script exits without doing anything
The file test.php is deleted
A notice is thrown because $argv[0] is not defined and the script fails.
$argv[0]
6.Considering the following code which of the statements below is true ?
class entity { public $name; } $human = new entity(); $dog = new entity(); $human->name = 0; $dog->name = "";
($human == $dog)
($human === $dog)
($human->name == $dog->name)
7.How does Opcode Cache improve performance in PHP 5.5+ ?
Opcode Cache stores objects in memory so that they can be accessed directly by other processes.
Opcode Cache stores database query results thus eliminating the need of executing those queries again
OPcache stores precompiled script bytecode in memory, thus removing the need to load and parse scripts on each request.
8.What happens if you execute the code below ?
<?php class someclass { public $someprop; function __construct() { $this->someprop = 1; } } function somefunc(&$instance) { unset($instance); } $instance = new someclass; somefunc($instance); var_dump($instance);
NULL
object(someclass)#1 (1) { ["someprop"]=> int(1) }
Warning (Only variables can be passed by refence) NULL
9.How do you access standard I/O and error streams ?
Use stdin(), stdout() and stderr() functions
PHP::STDIN, PHP::STDOUT and PHP::STDERR class constants
Use PHP::stdin(), PHP::stdout() and PHP::stderr() class functions
STDIN, STDOUT and STDERR constants
10.What is the output of this code snippet? $a = array(0.001 => 'b', .1 => 'c'); var_dump($a);
What is the output of this code snippet? $a = array(0.001 => 'b', .1 => 'c'); var_dump($a);
An empty array
0.001 => 'b', .1 => c
0 => 'c'
'0.001' => 'b', '0.1' => c'
A Syntax Error
11.What is the output of the following code block? $array = array(1 => 0, 2, 3, 4); array_splice($array, 3, count($array), array_merge(array('x'), array_slice($array, 3))); var_dump($array);
What is the output of the following code block? $array = array(1 => 0, 2, 3, 4); array_splice($array, 3, count($array), array_merge(array('x'), array_slice($array, 3))); var_dump($array);
1 => 1, 2 => 2, 3 => x, 4 => 4
0 => 1, 2 => 2, 3 => 3, 4 => 4, x => 3
0 => 0, 1 => 2, 2 => 3, 3 => x, 4 => 4
0 => x, 1 => 0, 2 => 1, 3 => 2, 4 => 3
1 => 1, 3 => x, 2 => 2, 4 => 4
12.Which key will not be displayed from the following code block? $array = array('a' => 'John', 'b' => 'Coggeshall', 'c' => array('d' => 'John', 'e' => 'Smith')); function display($item, $key) { print "$key => $item\n"; } array_walk_recursive($array, "display");
Which key will not be displayed from the following code block? $array = array('a' => 'John', 'b' => 'Coggeshall', 'c' => array('d' => 'John', 'e' => 'Smith')); function display($item, $key) { print "$key => $item\n"; } array_walk_recursive($array, "display");
d
c
b
a
They all will be displayed
13.The ____ construct is particularly useful to assign your own variable names to values within an array.
The ____ construct is particularly useful to assign your own variable names to values within an array.
array_get_variables
current
each
import_variables
list
14.Which of the following are valid PHP variables?
Which of the following are valid PHP variables?
@$foo
&$variable
${0x0}
$0x0
15.What is the output of the following PHP script? $a = 1; $b = 2.5; $c = 0xFF; $d = $b + $c; $e = $d * $b; $f = ($d + $e) % $a; print ($f + $e);
What is the output of the following PHP script? $a = 1; $b = 2.5; $c = 0xFF; $d = $b + $c; $e = $d * $b; $f = ($d + $e) % $a; print ($f + $e);
643.75
432
643
257
432.75
16.What is the output of the following? $a = 010; $b = 0xA; $c = 2; print $a + $b + $c;
What is the output of the following? $a = 010; $b = 0xA; $c = 2; print $a + $b + $c;
20
22
$a is an invalid value
2
17.Which one of the following XML declarations is NOT valid?
Which one of the following XML declarations is NOT valid?
<?xml version="1.0" ?>
<?xml version="1.1" encoding="UTF-8" ?>
<?xml standalone="no" ?>
<?xml standalone="1" ?>
18.How does one access standard input/output and error streams in PHP 5?
How does one access standard input/output and error streams in PHP 5?
19.How to access standard error stream in PHP ?
How to access standard error stream in PHP ?
$stderr = STDERR;
$stderr = fopen("php://stderr", "w");
$stderr = stderr("w")
$stderr = fwrite("php://stderr");
20.When checking to see if two variables contain the same instance of an object, which of the following comparisons should be used?
When checking to see if two variables contain the same instance of an object, which of the following comparisons should be used?
if($obj1->equals($obj2) && ($obj1 instanceof $obj2))
if($obj1->equals($obj2))
if($obj1 instanceof $obj2)
if($obj1 === $obj2)
21.In PHP 5 you can use the ______ operator to ensure that an object is of a particular type. You can also use _______ in the function declaration.
In PHP 5 you can use the ______ operator to ensure that an object is of a particular type. You can also use _______ in the function declaration.
instanceof, is_a
instanceof, type-hinting
type, instanceof
===, type-hinting
===, is_a
22.What is the output of the following script? class ClassOne { protected $a = 10; public function changeValue($b) { $this->a = $b; } } class ClassTwo extends ClassOne { protected $b = 10; public function changeValue($b) { $this->b = 10; parent::changeValue($this->a + $this->b); } public function displayValues() { print "a: {$this->a}, b: {$this->b}\n"; } } $obj = new ClassTwo(); $obj->changeValue(20); $obj->changeValue(10); $obj->displayValues();
What is the output of the following script? class ClassOne { protected $a = 10; public function changeValue($b) { $this->a = $b; } } class ClassTwo extends ClassOne { protected $b = 10; public function changeValue($b) { $this->b = 10; parent::changeValue($this->a + $this->b); } public function displayValues() { print "a: {$this->a}, b: {$this->b}\n"; } } $obj = new ClassTwo(); $obj->changeValue(20); $obj->changeValue(10); $obj->displayValues();
a: 30, b: 30
a: 30, b: 20
a: 30, b: 10
a: 20, b: 20
a: 10, b: 10
23.To ensure that a given object has a particular set of methods, you must provide a method list in the form of an ________ and then attach it as part of your class using the ________ keyword.
To ensure that a given object has a particular set of methods, you must provide a method list in the form of an ________ and then attach it as part of your class using the ________ keyword.
array, interface
interface, implements
interface, extends
instance, implements
access-list, instance
24. Which of the following list of potential data sources should be considered trusted?
Which of the following list of potential data sources should be considered trusted?
$_ENV
$_GET
$__COOKIE
$_SERVER
None of the above
25.What is the best measure one can take to prevent a cross-site request forgery?
What is the best measure one can take to prevent a cross-site request forgery?
Disallow requests from outside hosts
Add a secret token to all form submissions
Turn off allow_url_fopen in php.ini
Filter all output
Filter all input
26.When implementing a permissions system for your Web site, what should always be done with regards to the session?
When implementing a permissions system for your Web site, what should always be done with regards to the session?
You should not implement permission systems using sessions
Sessions should be cleared of all data and re-populated
The session key should be regenerated
The session should be destroyed
27.Consider the following script: $oranges = 10; $apples = 5; $string = "I have %d apples and %d oranges"; ??????? What could be placed in place of ?????? to output the string: "I have 5 apples and 10 oranges"
Consider the following script: $oranges = 10; $apples = 5; $string = "I have %d apples and %d oranges"; ??????? What could be placed in place of ?????? to output the string: "I have 5 apples and 10 oranges"
str_format($string, $apples, $oranges);
print($string, $apples, $oranges);
printf($string, $apples, $oranges);
print sprintf($apples, $oranges);
sprintf($string, $oranges, $apples);
28.If regular expressions must be used, in general which type of regular expression functions available to PHP is preferred for performance reasons?
If regular expressions must be used, in general which type of regular expression functions available to PHP is preferred for performance reasons?
strtok() using regular expressions
preg_* regular expression functions
parse_str() using regular expressions
strregex* regular expression functions
ereg* regular expression functions
29.If you would like to change the session ID generation function, which of the following is the best approach for PHP 5?
If you would like to change the session ID generation function, which of the following is the best approach for PHP 5?
Set the session.hash_function INI configuration directive
Use the session_set_id_generator() function
Set the session id by force using the session_id() function
Use the session_regenerate_id() function
Implement a custom session handler
30.Consider the following HTML fragment: <select name="???????" multiple> <option value="1">Item #1</option> <!-- ... more options ... --> </select> Which of the following name attributes should be used to capture all of the data from the user in PHP?
Consider the following HTML fragment: <select name="???????" multiple> <option value="1">Item #1</option> <!-- ... more options ... --> </select> Which of the following name attributes should be used to capture all of the data from the user in PHP?
myselectbox=array()
myselectbox[]
myselectbox['multiple']
myselectbox{'multiple'}
myselectbox