1.What output will this code produce ?
<?php class Disney { public $cartoon; function __construct($cartoon) { $this->cartoon = $cartoon; } } $disney = new Disney("The Beauty and The Beast"); $waltDisney = $disney; $waltDisney->cartoon = "Pinocchio"; echo $disney->cartoon;
"Pinocchio" because $waltDisney and $Disney are pointing to the same object
"The Beauty and The Beast" because the $cartoon property in the $waltDisney object was changed
NULL because the Disney class was not instanciated inside the $waltDisney variable
2.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
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.What is the output of the code below ?
<?php $a = array(); $a[0] = 1; unset($a[0]); echo ($a != null) ? 'True' : 'False';
True
False
Parse Error
5.Which of the statements about traits below are true ?
traits
PHP is "single inheritance" so traits allow coders to reuse sets of methods from the trait freely in several independent classes
An inherited member from a base class is overridden by a member inserted by a Trait, but members from the current class override Trait methods.
If two Traits insert a method with the same name in a class that uses them, a fatal error is produced and this naming conflict can not be bypassed
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.When dealing with cloned objects in PHP, which of the following statements are true ?
The programmer can make use of the __clone() magic method to stop an object from being cloned.
__clone()
As of PHP 7.0.0, members of cloned objects can be accessed in a single expression without any assignments... Like this: (clone new DateTime())->format('Y');
(clone new DateTime())->format('Y');
The __clone() magic method of a class is called before the actual cloning of the object occurs allowing the programmer to alter values before the cloning process begins.
8.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.
9.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
10.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
11.What is the best way to iterate and modify every element of an array using PHP 5?
What is the best way to iterate and modify every element of an array using PHP 5?
You cannot modify an array during iteration.
for($i = 0; $i < count($array); $i++) { /* ... * / }
foreach($array as $key => &$val) { /* ... * / }
foreach($array as $key => $val) { /* ... * / }
while(list($key, $val) = each($array)) { /* ... * / }
12.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
13.Given a PHP value, which sample shows how to convert the value to JSON?
Given a PHP value, which sample shows how to convert the value to JSON?
$string = json_encode($value);
$string = Json::encode($value);
$json = new Json($value); $string = $json->__toString();
$value = (object) $value; $string = $value->__toJson();
14.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" ?>
15.Consider the following table data and PHP code. What is the outcome? Table data (table name "users" with primary key "id"): id name email ------- ----------- ------------------- 1 anna [email protected] 2 betty [email protected] 3 clara [email protected] 5 sue [email protected] PHP code (assume the PDO connection is correctly established): $dsn = 'mysql:host=localhost;dbname=exam'; $user = 'username'; $pass = '********'; $pdo = new PDO($dsn, $user, $pass); $cmd = "SELECT * FROM users WHERE id = :id"; $stmt = $pdo->prepare($cmd); $id = 3; $stmt->bindParam('id', $id); $stmt->execute(); $stmt->bindColumn(3, $result); $row = $stmt->fetch(PDO::FETCH_BOUND);
Consider the following table data and PHP code. What is the outcome? Table data (table name "users" with primary key "id"): id name email ------- ----------- ------------------- 1 anna [email protected] 2 betty [email protected] 3 clara [email protected] 5 sue [email protected] PHP code (assume the PDO connection is correctly established): $dsn = 'mysql:host=localhost;dbname=exam'; $user = 'username'; $pass = '********'; $pdo = new PDO($dsn, $user, $pass); $cmd = "SELECT * FROM users WHERE id = :id"; $stmt = $pdo->prepare($cmd); $id = 3; $stmt->bindParam('id', $id); $stmt->execute(); $stmt->bindColumn(3, $result); $row = $stmt->fetch(PDO::FETCH_BOUND);
The database will return no rows.
The value of $row will be an array.
The value of $result will be empty.
The value of $result will be '[email protected]'.
16.What is the best way to ensure that a user-defined function is always passed an object as its single parameter?
What is the best way to ensure that a user-defined function is always passed an object as its single parameter?
function myfunction(stdClass $a)
function myfunction($a = stdClass)
Use is_object() within the function
There is no way to ensure the parameter will be an object.
function myfunction(Object $a)
17.What would you replace ??????? with, below, to make the string Hello, World! be displayed? function myfunction() { /* ??????? */ print $string; } myfunction("Hello, World!");
What would you replace ??????? with, below, to make the string Hello, World! be displayed? function myfunction() { /* ??????? */ print $string; } myfunction("Hello, World!");
There is no way to do this.
$string = $argv[1];
$string = $_ARGV[0];
list($string) = func_get_args();
$string = get_function_args();
18.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");
19.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)
20.How can you modify the copy of an object during a clone operation?
How can you modify the copy of an object during a clone operation?
Put the logic in the object's constructor to alter the values
Implment your own function to do object copying
Implement the object's __clone() method
Implement __get() and __set() methods with the correct logic
Implement the __copy() method with the correct logic
21.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
22.Which of the following php.ini directives should be disabled to improve the outward security of your application?
Which of the following php.ini directives should be disabled to improve the outward security of your application?
safe_mode
magic_quotes_gpc
register_globals
display_errors
allow_url_fopen
23.Consider the following code: header("Location: {$_GET['url']}\"); Which of the following values of $_GET['url'] would cause session fixation?
Consider the following code: header("Location: {$_GET['url']}\"); Which of the following values of $_GET['url'] would cause session fixation?
Session Fixation is not possible with this code snippet
http://www.zend.com/?PHPSESSID=123
PHPSESSID%611243
Set-Cookie%3A+PHPSESSID%611234
http%3A%2F%2Fwww.zend.com%2F%0D%0ASet-Cookie%3A+PHPSESSID%611234
24.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
None of the above
25.A fingerprint of a string can be determined using which of the following?
A fingerprint of a string can be determined using which of the following?
md5()
hash()
fingerprint()
26.Which of the following is the best way to split a string on the "-=-" pattern?
Which of the following is the best way to split a string on the "-=-" pattern?
They all are equally proper methods
str_split($string, strpos($string, "-=-"))
preg_split("-=-", $string);
explode("-=-", $string);
27.Identify the best approach to compare two variables in a binary-safe fashion
Identify the best approach to compare two variables in a binary-safe fashion
Both strcmp() and $a === $b
$a == $b
$a === $b
str_compare()
strstr()
28.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);
29.Which PCRE regular expression will match the string PhP5-rocks
Which PCRE regular expression will match the string PhP5-rocks
/^[hp1-5]*\-.*/i
/[hp1-5]*\-.?/
/[hp][1-5]*\-.*/
/[PhP]{3}[1-5]{2,3}\-.*$/
/[a-z1-5\-]*/
30.One can ensure that headers can always be sent from a PHP script by doing what?
One can ensure that headers can always be sent from a PHP script by doing what?
Enable header buffering in PHP 5
Set the header.force INI directive to true
Enable output buffering in PHP 5
There is no way to ensure that headers can always be set, they must always be checked