class interface
Which of the following is correct? (Choose 2)
A. A class can extend more than one class.
B. A class can implement more than one class.
C. A class can extend more than one interface.
D. A class can implement more than one interface.
E. An interface can extend more than one interface.
F. An interface can implement more than one interface. |
|
|
DB
You'd like to use the class MyDBConnection that's defined in the
MyGreatFramework\MyGreatDatabaseAbstractionLayer namespace, but you want to
minimize as much as possible the length of the class name you have to type. What would
you do?
A. Import the MyGreatFramework namespace
B. Import the MyGreatFramework\MyGreatDatabaseAbstractionLayer namespace
C. Alias MyGreatFramework\MyGreatDatabaseAbstractionLayer\MyDBConnection to a shorter name
D. Alias MyGreatFramework\MyGreatDatabaseAbstractionLayer to a shorter name |
JSON convert
Given a PHP value, which sample shows how to convert the value to JSON?
A. $string = json_encode($value);
B. $string = Json::encode($value);
C. $json = new Json($value); $string = $json->__toString();
D. $value = (object) $value; $string = $value->__toJson(); |
JSON convert
Given a JSON-encoded string, which code sample correctly indicates how to decode the
string to native PHP values?
A. $json = new Json($jsonValue); $value = $json->decode();
B. $value = Json::decode($jsonValue);
C. $value = json_decode($jsonValue);
D. $value = Json::fromJson($jsonValue); |
query
When a query that is supposed to affect rows is executed as part of a transaction, and
reports no affected rows, it could mean that: (Choose 2)
A. The transaction failed
B. The transaction affected no lines
C. The transaction was rolled back
D. The transaction was committed without error |
sql
Transactions should be used to: (Choose 2)
A. Prevent errors in case of a power outage or a failure in the SQL connection
B. Ensure that the data is properly formatted
C. Ensure that either all statements are performed properly, or that none of them are.
D. Recover from user errors |
msql
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 alpha@example.com
2 betty beta@example.org
3 clara gamma@example.net
5 sue sigma@example.info
PHP code(assume tha PDO connection is correctly established):
$dsn = 'mysql:host = localhost;dbname=exam':
$user = 'username';
$pass = ' *';
$pdo - new PDO($dsn, $user, $pass);
$cmd = 'SELECT * FOM 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);
A. Database will return no rows
B. The vaule of $row will be an array
C. The vaule of $result will be empty
D. The value of $result will be 'gamma@example.net' |
msql
What is the preferred method for preventing SQL injection?
A. Always using prepared statements for all SQL queries.
B. Always using the available database-specific escaping functionality on all variables prior to building the SQL query.
C. Using addslashes() to escape variables to be used in a query.
D. Using htmlspecialchars() and the available database-specific escaping functionality to escape variables to be used in a query. |
Output Test
Consider the following table data and PHP code. What is a possible outcome?
Table data (table name "users" with primary key "id"):
id name email
------- ----------- -------------------
1 anna alpha@example.com
2 betty beta@example.org
3 clara gamma@example.net
5 sue sigma@example.info
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 name, email FROM users LIMIT 1";
$stmt = $pdo->prepare($cmd);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_BOTH);
$row = $result[0];
A. The value of $row is array(0 => 'anna', 1 => 'alpha@example.com')
.
B. The value of $row is array('name' => 'anna', 'email' => 'alpha@example.com')
.
C. The value of $row is array(0 => 'anna', 'name' => 'anna', 1 => 'alpha@example.com', 'email' => 'alpha@example.com')
.
D. The value of $result is array('anna' => 'alpha@example.com')
. |
Output Test
Given the following code, what is correct?
function f(stdClass &$x = NULL) { $x = 42; }
$z = new stdClass;
f($z);
var_dump($z);
A. Error: Typehints cannot be NULL
B. Error: Typehints cannot be references
C. Result is NULL
D. Result is object of type stdClass
E. Result is 42 |
msql
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 alpha@example.com
2 betty beta@example.org
3 clara gmma@example.net
5 sue sigma@example.info
PHP code(assume the PDO connection is correctly established ):
$dsn = 'mysql:host=localhost;dbname=exam';
$user= 'username';
$pass = ' ';
$pdo = new PDO($dsn, $user, $pass);
try{
$cmd = "INSER INTO users (id, name, email) VALUES (:id, :name, :email)";
$stmt = $pdo ->prepare($cmd);
$stmt -> bindValue('id', 1);
$stmt -> bindValue('name', 'anna');
$stmt -> bindValue( 'email', 'alpha@example.com');
$stmt->execute();
echo "Succes!";
}catch (PDOException $e){
echo "Faliure!";
throw $e;
A.The INSERT will succeed and the user will see the "Success!" message
B. The INSERT will fail because of a primary key violation, and user will see "Success!" message
C. The INSERT will fail because of a primary key violation , and the user will see a PDO warring message
D. The INSERT will fail because of a primary key vioaltion, and the user will see the "Faliure!" messsage |
msql
An unbuffered database query will: (Choose 2)
A. Return the first data faster
B. Return all data faster
C. Free connection faster for others scripts to use
D. Use less memory |
msql
Consider the following table data and PHP code, and assume that the database supports
transactions. What is the outcome?
Table data (table name "users" with primary key "id"):
id name email
------- ----------- -------------------
1 anna alpha@example.com
2 betty beta@example.org
3 clara gamma@example.net
5 sue sigma@example.info
PHP code (assume the PDO connection is correctly established):
$dsn = 'mysql:host=localhost;dbname=exam';
$user = 'username';
$pass = ' **';
$pdo = new PDO($dsn, $user, $pass);
try {
$pdo->exec("INSERT INTO users (id, name, email) VALUES (6, 'bill',
'delta@example.com')");
$pdo->begin();
$pdo->exec("INSERT INTO users (id, name, email) VALUES (7, 'john',
'epsilon@example.com')");
throw new Exception();
} catch (Exception $e) {
$pdo->rollBack();
A. The user 'bill' will be inserted, but the user 'john' will not be.
B. Both user 'bill' and user 'john' will be inserted.
C. Neither user 'bill' nor user 'john' will be inserted.
D. The user 'bill' will not be inserted, but the user 'john' will be. |
form techique
The following form is loaded in a browser and submitted, with the checkbox activated:
<form method="post">
<input type="checkbox" name="accept" />
</form>
In the server-side PHP code to deal with the form data, what is the value of
$_POST['accept'] ?
A. accept
B. ok
C. true
D. on |
form techique
An HTML form has two submit buttons. After submitting the form, how can you determine
with PHP which button was clicked?
A. An HTML form may only have one button.
B. You cannot determine this with PHP only. You must use JavaScript to add a value to the URL depending on which button has been clicked.
C. Put the two buttons in different forms, but make sure they have the same name.
D. Assign name and value attributes to each button and use $_GET or $_POST to find out which button has been clicked. |
form techique
An HTML form contains this form element:
[6]
The user clicks on the image to submit the form. How can you now access the relative
coordinates of the mouse click?
A. $_FILES['myImage']['x'] and $_FILES['myImage']['y']
B. $_POST['myImage']['x'] and $_POST['myImage']['y']
C. $_POST['myImage.x'] and $_POST['myImage.y']
D. $_POST['myImage_x'] and $_POST['myImage_y'] |
form techique
Which of the following techniques ensures that a value submitted in a form can only be yes
or no ?
A. Use a select list that only lets the user choose between yes and no .
B. Use a hidden input field that has a value of yes or no .
C. Enable the safe_mode configuration directive.
D. None of the above. |
constant
What does the __FILE__ constant contain?
A. The filename of the current script.
B. The full path to the current script.
C. The URL of the request made.
D. The path to the main script. |
|
|
Output Test
What is the output of the following code?
class Base {
protected static function whoami() {
echo "Base ";
public static function whoareyou() {
static::whoami();
class A extends Base {
public static function test() {
Base::whoareyou();
self::whoareyou();
parent::whoareyou();
A. :whoareyou(); static::whoareyou(); } public static function whoami() { echo "A "; } } class B extends A { public static function whoami() { echo "B "; } }
B. :test();
C. B B B B B
D. Base A Base A B
E. Base B B A B
F. Base B A A B |
Output Test
What is the output of the following code?
$a = 3;
switch ($a) {
case 1: echo 'one'; break;
case 2: echo 'two'; break;
default: echo 'four'; break;
case 3: echo 'three'; break;
A. one
B. two
C. three
D. four |
Output Test
How many elements doeas the array $matches from the following code contain?
$str = "The cat sat on the roof of their house.";
$mathes = preg_split("/(the)/i" , $str, -1, PREG_SPLIT_DELIM_CAPTURE);
A. 2
B.3
C.4
D. 7
E. 9 |
Output Test
What is the output of the following code?
class Number {
private $v;
private static $sv = 10;
public function __construct($v) { $this->v = $v; }
public function mul() {
return static function ($x) {
return isset($this) ? $this->v$x : self::$sv$x;
};
$one = new Number(1);
$two = new Number(2);
$double = $two->mul();
$x = Closure::bind($double, null, 'Number');
echo $x(5);
A. 5
B. 10
C. 50
D. Fatal error |
Output Test
How many elements does the array $pieces contain after the following piece of code has
been executed?
$pieces = explode("/", "///");
A. 0
B. 3
C. 4
D. 5 |
Output Test
Given the following code, what will the output be:
trait MyTrait {
private $abc = 1;
public function increment() {
$this->abc++;
public function getValue() {
return $this->abc;
class MyClass {
use MyTrait;
public function incrementBy2() {
$this->increment();
$this->abc++;
$c = new MyClass;
$c->incrementBy2();
var_dump($c->getValue());
A. Fatal error: Access to private variable MyTrait::$abc from context MyClass
B. Notice: Undefined property MyClass::$abc
C. int(2)
D. int(3)
E. NULL |
Output Test
What is the return value of the following code: substr_compare("foobar", "bar", 3);
A. -1
B. 1
C. TRUE
D. 0
E. FALSE |
Output Test
What is the output of the following code?
class T
const A = 42 + 1;
echo T :: A;
A. 42
B. 43
C. parse error |
Output Test
Consider the following code. What can be said about the call to file_get_contents?
$getdata = "foo=bar";
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $getdata
);
$context = stream_context_create($opts);
$result = file_get_contents('http://example.com/submit.php', false, $context);
A. A GET request will be performed on http://example.com/submit.php
B. A POST request will be performed on http://example.com/submit.php
C. An error will be displayed |
Output Test
Given the following array:
$a = array(28, 15, 77, 43);
Which function will remove the value 28 from $a?
A. array_shift()
B. array_pop()
C. array_pull()
D. array_unshift() |
Output Test
You want to access the 3rd character of a string, contained in the variable $test. Which of
the following possibilites work? (Choose 2)
A. echo $test(3);
B. echo $test[2];
C. echo $test(2);
D. echo $test{2};
E. echo $test{3}; |
Output Test
What will the $array array contain at the end of this script?
function modifyArray (&$array)
foreach ($array as &$value)
$value = $value + 1;
$value = $value + 2;
$array = array (1, 2, 3);
modifyArray($array);
A. 2, 3, 4
B. 2, 3, 6
C. 4, 5, 6
D. 1, 2, 3 |
Output Test
Which line of code can be used to replace the INSERT comment in order to output "hello"?
class C {
public $ello = 'ello';
public $c;
public $m;
function __construct($y) {
$this->c = static function($f) {
// INSERT LINE OF CODE HERE
};
$this->m = function() {
return "h";
};
$x = new C("h");
$f = $x->c;
echo $f($x->m);
A. return $this->m() . "ello";
B. return $f() . "ello";
C. return "h". $this->ello;
D. return $y . "ello"; |
Output Test
What is the output of the following code?
echo "1" + 2 * "0x02";
A. 1
B. 3
C. 5
D. 20
E. 7 |
Output Test
What is the output of the following code?
class a
public $val;
function renderVal (a $a)
if ($a) {
echo $a->val;
renderVal (null);
A. A syntax error in the function declaration line
B. An error, because null is not an instance of 'a'
C. Nothing, because a null value is being passed to renderVal()
D. NULL |
Output Test
Consider the following code:
$result = $value1 ??? $value2;
Which operator needs to be used instead of ??? so that $result equals $value1 if $value1
evaluates to true, and equals $value2 otherwise? Just state the operator as it would be
required in the code. |
Output Test
What will the following code piece print?
echo strtr('Apples and bananas', 'ae', 'ea')
A. Applas end benenes
B. Epplas end benenes
C. Apples and bananas
D. Applas end bananas |
Output Test
What is the output of the following code?
echo '1' . (print '2') + 3;
A. 123
B. 213
C. 142
D. 214
E. Syntax error |
Output Test
Which string will be returned by the following function call?
$test = '/etc/conf.d/wireless';
substr($test, strrpos($test, '/')); // note that strrpos() is being called, and not strpos()
A. ""
B. "/wireless"
C. "wireless"
D. "/conf.d/wireless"
E. "/etc" |
Output Test
What is the output of the following code?
class C {
public $x = 1;
function __construct() { ++$this->x; }
function __invoke() { return ++$this->x; }
function __toString() { return (string) --$this->x; }
$obj = new C();
echo $obj();
A. 0
B. 1
C. 2
D. 3 |
Output Test
Which interfaces could class C implement in order to allow each statement in the following
code to work? (Choose 2)
$obj = new C();
foreach ($obj as $x => $y) {
echo $x, $y;
A. Iterator
B. ArrayAccess
C. IteratorAggregate
D. ArrayObject |
Output Test
//s1.php
sesion_start();
sleep(1);
//s2.php
sesion_start();
sleep(2);
//s3.php
sesion_start();
sleep(3);
|
Which of the following statements is true? (Choose two.)
A. The total execution time for all 3 requests will be the maximum of the longest sleep() call
B. The requests may be processed out of order
C. The requests are guaranteed to be executed in order
D. Concurrent requests will be blocked until the session lock is released
Answer: A
Output Test
The following form is loaded in a recent browser and submitted, with the second select
option selected:
<form method="post">
<select name="list">
<option>one</option>
<option>two</option>
<option>three</option>
</select>
</form>
In the server-side PHP code to deal with the form data, what is the value of $_POST['list'] ?
A. 1
B. 2
C. two
D. null |
Output Test
Which value will be assigned to the key 0 in the following code?
$a = array(true, '0'=> false, false=>true ); |
Output Test
What is the output?
class Number {
private $v = 0;
public function __construct($v) { $this->v = $v; }
public function mul() {
return function ($x) { return $this->v * $x; };
$one = new Number(1);
$two = new Number(2);
$double = $two->mul()->bindTo($one);
echo $double(5);
|
Output Test
How should class MyObject be defined for the following code to work properly?
Assume
$array is an array and MyObject is a user-defined class.
$obj = new MyObject();
array_walk($array, $obj);
A. MyObject should extend class Closure
B. MyObject should implement interface Callable
C. MyObject should implement method __call
D. MyObject should implement method __invoke |
Output Test
What will the following code print out?
$str = '✔ one of the following';
echo str_replace('✔', 'Check', $str);
A. Check one of the following
B. one of the following
C. ✔ one of the following |
Output Test
What is the output of the following code?
var_dump(boolval([]));
A. bool(true)
B. bool(false) |
Output Test
Assuming UTF-8 encoding, what is the value of $count?
$data= $1a2
;
$count = strlen($data);
A. 0
B. 4
C. 5
D. 7 |
Output Test
Given the following DateTime objects, what can you use to compare the two dates and
indicate that $date2 is the later of the two dates?
$date1 = new DateTime('2014-02-03');
$date2 = new DateTime('2014-03-02');
A. $date2 > $date1
B. $date2 < $date1
C. $date1->diff($date2) < 0
D. $date1->diff($date2) > 0 |
Output Test
What is the output of the following code?
$f = function () { return "hello"; };
echo gettype($f);
A. hello
B. string
C. object
D. function |
Output Test
What is the output of the following code?
$a = array('a', 'b'=>'c');
echo property_exists((object) $a, 'a')?'true':'false';
echo '-';
echo property_exists((object) $a, 'b')?'true':'false';
A. false-false
B. false-true
C. true-false
D. true-true |
Output Test
What is the output of the following code?
class Number {
private $v = 0;
public function __construct($v) { $this->v = $v; }
public function mul() {
return function ($x) { return $this->v * $x; };
$one = new Number(1);
$two = new Number(2);
$double = $two->mul()->bindTo($one);
echo $double(5); |
Output Test
What is the output of this code?
$world = 'world';
echo <<<'TEXT'
hello $world
TEXT;
A. hello world
B. hello $world
C. PHP Parser error |
Output Test
What is the output of the following code?
function z($x) {
return function ($y) use ($x) {
return str_repeat($y, $x);
};
$a = z(2);
$b = z(3);
echo $a(3) . $b(2);
A. 22333
B. 33222
C. 33322
D. 222333 |
Output Test
What is the output of the following code?
class A{
public $a = 1;
public function__construct($a) {$this->a= $a;}
public function mul(){
return function ($x){
return $this->$a*$x;
};
$a= newA(2);
$a->mul = function($x){
return $x*$x;
};
$m = $a->mul();
echo $m(3);
A.9
B. 6
C. 0
D. 3 |
Output Test
How many times will the function counter() be executed in the following code?
function counter($start, &$stop)
if ($stop > $start)
return;
counter($start--, ++$stop);
$start = 5;
$stop = 2;
counter($start, $stop);
A. 3
B. 4
C. 5
D. 6 |
Output Test
What is the output of the following code?
try {
class MyException extends Exception {};
try {
throw new MyException;
catch (Exception $e) {
echo "1:";
throw $e;
catch (MyException $e) {
echo "2:";
throw $e;
catch (Exception $e) {
echo get_class($e);
A. A parser error, try cannot be followed by multiple catch
B. 1:
C. 2:
D. 1:Exception
E. 1:MyException
F. 2:MyException
G. MyException |
Output Test
What is the output of the following code?
class Bar {
private $a = 'b';
public $c = 'd';
$x = (array) new Bar();
echo array_key_exists('a', $x) ? 'true' : 'false';
echo '-';
echo array_key_exists('c', $x) ? 'true' : 'false';
A. false-false
B. false-true
C. true-false
D. true-true |
Output Test
What is the output of the following code?
$text = 'This is text';
$text1 = <<<'TEXT'
$text
TEXT;
$text2 = <<<TEXT
$text1
TEXT;
echo "$text2";
A. This is text
B. $text
C. $text1
D. $text2 |
Output Test
What is the output of the following code?
function ratio ($x1 = 10, $x2)
if (isset ($x2)) {
return $x2 / $x1;
echo ratio (0);
A. 0
B. An integer overflow error
C. A warning, because $x1 is not set
D. A warning, because $x2 is not set
E. A floating-point overflow error
F. Nothing |
Output Test
What is the output of the following code?
function increment ($val)
$_GET['m'] = (int) $_GET['m'] + 1;
$_GET['m'] = 1;
echo $_GET['m']; |
Output Test
What will be the result of the following operation?
$a = array_merge([1,2,3] + [4=>1,5,6]);
echo $a[2];
A. 4
B. 3
C. 2
D. false
E. Parse error |
Output Test
What is the output of the following code?
class Test {
public $var=1;
}
function addMe (Test $t){
$t->var++;
}
$t = new Test();
addMe($t);
echo $t->var;
A. 1
B. 2
C. null |
Output Test
What is the output of the following code?
function fibonacci (&$x1 = 0, &$x2 = 1)
$result = $x1 + $x2;
$x1 = $x2;
$x2 = $result;
return $result;
for ($i = 0; $i < 10; $i++) {
echo fibonacci() . ',';
A. An error
B. 1,1,1,1,1,1,1,1,1,1,
C. 1,1,2,3,5,8,13,21,34,55,
D. Nothing |
Output Test
What is the output of the following code?
function append($str)
$str = $str.'append';
function prepend(&$str)
$str = 'prepend'.$str;
$string = 'zce';
append(prepend($string));
echo $string;
A. zceappend
B. prependzceappend
C. prependzce
D. zce |
Output Test
Consider the following code. What change must be made to the class for the code to work
as written?
class Magic {
protected $v = array("a" => 1, "b" => 2, "c" => 3);
public function __get($v) {
return $this->v[$v];
$m = new Magic();
$m->d[] = 4;
echo $m->d[0];
A. Nothing, this code works just fine.
B. Add __set method doing $this->v[$var] = $val
C. Rewrite __get as: public function __get(&$v)
D. Rewrite __get as: public function &__get($v)
E. Make __get method static |
Output Test
In the following code, which classes can be instantiated?
abstract class Graphics {
abstract function draw($im, $col);
abstract class Point1 extends Graphics {
public $x, $y;
function __construct($x, $y) {
$this->x = $x;
$this->y = $y;
function draw($im, $col) {
ImageSetPixel($im, $this->x, $this->y, $col);
class Point2 extends Point1 { }
abstract class Point3 extends Point2 { }
A. Graphics
B. Point1
C. Point2
D. Point3
E. None, the code is invalid |
Output Test
How can the id attribute of the 2nd baz element from the XML string below be retrieved
from the SimpleXML object
found inside $xml?
<?xml version='1.0'?>
<foo>
<bar>
<baz id="1">One</baz>
<baz id="2">Two</baz>
</bar>
</foo>
A. $xml->getElementById('2');
B. $xml->foo->bar->baz[2]['id']
C. $xml->foo->baz[2]['id']
D. $xml->foo->bar->baz[1]['id']
E. $xml->bar->baz[1]['id'] |
Output Test
What will be the output value of the following code?
$array = array(1,2,3);
while (list(,$v) = each($array));
var_dump(current($array));
A. bool(false)
B. int(3)
C. int(1)
D. NULL
E. Array |
Output Test
What is the return value of the following code?
strpos("me myself and I", "m", 2)
A. 2
B. 3
C. 4
D. 0
E. 1 |
Output Test
What is the output of the following code?
namespace MyNamespace;
class test{
}
echo Test :: class;
A. MyNamespace\Test
B. empty string
C. parse error
D. Test |
Output Test
What is the result of the following code?
define('PI', 3.14);
class T
const PI = PI;
class Math
const PI = T::PI;
echo Math::PI;
A. Parse error
B. 3.14
C. PI
D. T::PI |
Output Test
What is the output of the following code?
function increment (&$val)
return $val + 1;
$a = 1;
echo increment ($a);
echo increment ($a); |
Output Test
What is the output of the following code?
$a = ['1'=>'Apple', '3'=>'cactus', '5'=>'Elderflower'] + ['Bannana', 'fig' , 'dragon frouit'];
echo count($a); |
Output Test
What is the output of the following code?
class Test {
public function __call($name, $args)
call_user_func_array(array('static', "test$name"), $args);
public function testS($l) {
echo "$l,";
class Test2 extends Test {
public function testS($l) {
echo "$l,$l,";
$test = new Test2();
$test->S('A');
A. A,
B. A,A,
C. A,A,A,
D. PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback |
Output Test
what is the output of the following code?
$first = "second";
$second = "first";
echo $$$first;
A. "first"
B. "second"
C. an empty sting
D. an error |
Output Test
What is the output of the following code?
$a= 'a'; $b = 'b';
echo isset($c) ? $a.$b.$c : ($c = 'c') . 'd';
A. abc
B. cd
C. 0c |
Output Test
What is the output of the following code?
var_dump(boolval(-1));
A. bool(true)
B. bool(false) |
Output Test
An HTML form contains this form element:
<input type="file" name="myFile" />
When this form is submitted, the following PHP code gets executed:
move_uploaded_file(
$_FILES['myFile']['tmp_name'],
'uploads/' . $_FILES['myFile']['name']
);
Which of the following actions must be taken before this code may go into production?
(Choose 2)
A. Check with is_uploaded_file() whether the uploaded file $_FILES['myFile']['tmp_name'] is valid
B. Sanitize the file name in $_FILES['myFile']['name'] because this value is not consistent among web browsers
C. Check the charset encoding of the HTTP request to see whether it matches the encoding of the uploaded file
D. Sanitize the file name in $_FILES['myFile']['name'] because this value could be forged
E. Use $HTTP_POST_FILES instead of $_FILES to maintain upwards compatibility |
Output Test
What will be the result of the following operation?
array_combine(array("A","B","C"), array(1,2,3));
A. array("A","B","C",1,2,3)
B. array(1,2,3,"A","B",C")
C. array("A"=>1,"B"=>2,"C"=>3)
D. array(1=>"A",2=>"B",3=>"C")
E. array(1,2,3) |
Output Test
Given a DateTime object that is set to the first second of the year 2014, which of the following samples will correctly return a date in the format '2014-01-01 00:00:01'?
A. $datetime->format('%Y-%m-%d %h:%i:%s')
B. $datetime->format('%Y-%m-%d %h:%i:%s', array('year', 'month', 'day', 'hour', 'minute', 'second'))
C. $datetime->format('Y-m-d H:i:s')
D. $date = date('Y-m-d H:i:s', $datetime); |
Output Test
What is the output of the following code?
echo "22" + "0.2", 23 . 1;
A. 220.2231
B. 22.2231
C. 22.2,231
D. 56.2 |
Output Test
$world = 'world';
echo <<<'TEXT'
hello $world
TEXT;
|
What is the output of this code?
A. hello world
B. hello $world
C. PHP Parser error
answer: C
Output Test
What will be the output of the following code?
$a = array(0, 1, 2 => array(3, 4));
$a[3] = array(4, 5);
echo count($a, 1);
A. 4
B. 5
C. 8
D. None of the above |
Output Test
What is the output of the following code?
for ($i = 0; $i < 1.02; $i += 0.17) {
$a[$i] = $i;
echo count($a);
A. 0
B. 1
C. 2
D. 6
E. 7 |
Output Test
Given the following code, how can we use both traits A and B in the same class? (select all that apply)
trait A {
public function hello() {
return "hello";
public function world() {
return "world";
trait B {
public function hello() {
return "Hello";
public function person($name) {
return ":$name";
A. Rename the A::hello() method to a different name using A::hello as helloA;
B. Use B::hello() instead of A 's version using B::hello insteadof A
C. Use B::hello() instead of A 's version using use B::hello
D. Rename the A::hello() method to a different name using A::hello renameto helloA;
E. None of the above (both can be used directly) |
Output Test
In the following code, which line should be changed so it outputs the number 2:
class A {
protected $x = array(); / A /
public function getX() { / B /
return $this->x; / C /
$a = new A(); / D /
array_push($a->getX(), "one");
array_push($a->getX(), "two");
echo count($a->getX());
A. No changes needed, the code would output 2 as is
B. Line A, to: protected &$x = array();
C. Line B, to: public function &getX() {
D. Line C, to: return &$this->x;
E. Line D, to: $a =& new A(); |
Output Test
What is the output of the following code?
class Foo Implements ArrayAccess {
function offsetExists($k) { return true;}
function offsetGet($k) {return 'a';}
function offsetSet($k, $v) {}
function offsetUnset($k) {}
$x = new Foo();
echo array_key_exists('foo', $x)?'true':'false';
A. true
B. false |
Output Test
What is the output of the following code?
function increment ($val)
++$val;
$val = 1;
increment ($val);
echo $val; |
Output Test
What is the output of the following code?
function increment ($val)
$val = $val + 1;
$val = 1;
increment ($val);
echo $val; |
Output Test
What is the output of the following code?
var_dump(boolval(new StdClass()));
A. bool(true)
B. bool(false) |
Output Test
Consider the following code. Which keyword should be used in the line marked with
"KEYWORD" instead of "self" to make this code work as intended?
abstract class Base {
protected function __construct() {
public static function create() {
return new self(); // KEYWORD
abstract function action();
class Item extends Base {
public function action() { echo __CLASS__; }
$item = Item::create();
$item->action(); // outputs "Item" |
Output Test
What is the output of the following code?
$string = Good luck!
;
$start = 10;
var_dump (substr($string, $start));
A. string(0) “”
B. bool(false)
C. string(1) “!”
D. string(2) “k!” |
Output Test
Which of the following code snippets is correct? (Choose 2)
A. interface Drawable { abstract function draw(); }
B. interface Point { function getX(); function getY(); }
C. interface Line extends Point { function getX2(); function getY2(); }
D. interface Circle implements Point { function getRadius(); } |
Output Test
What is the output of the following code?
`class test {
public $value = 0;
function test() {
$this->value = 1;
function __construct() {
$this->value = 2;
$object = new test();
echo $object->value;`
A. 2
B. 1
C. 0
D. 3
E. No Output, PHP will generate an error message. |
Output Test
What is the output of the following code?
echo 0x33, ' monkeys sit on ', 011, ' trees.';
A. 33 monkeys sit on 11 trees.
B. 51 monkeys sit on 9 trees.
C. monkeys sit on trees.
D. 0x33 monkeys sit on 011 trees. |
Output Test
Which of the following expressions will evaluate to a random value from an array below?
$array = array("Sue","Mary","John","Anna");
A. array_rand($array);
B. array_rand($array, 1);
C. shuffle($array);
D. $array[array_rand($array)];
E. array_values($array, ARRAY_RANDOM); |
Output Test
After performing the following operations:
$a = array('a', 'b', 'c');
$a = array_keys(array_flip($a));
What will be the value of $a?
A. array('c', 'b', 'a')
B. array(2, 1, 0)
C. array('a', 'b', 'c')
D. None of the above |
|