1h 30m 00s
ID: 520
Which of the following are examples of the new engine executor models available in PHP 5?
ID: 789
Give the following expression: "$$foo['bar']". Which of the statements below are true?
ID: 63
You run the following PHP script:
$a = "b"; $b = 20; echo $$a;
What will be the output?
ID: 696
When working with unfamiliar code, what is the best way to find out in which file a class is defined ?
# Using the get_declared_classes() function: $classes = get_declared_classes(); var_dump($classes);
# Using ReflectionClass: $reflection = new ReflectionClass('ClassName'); echo $reflection->getFileName();
# Using the grep command to search through the application files: $out = array(); exec("grep -r 'Classname' .", $out); var_dump($out);
ID: 563
What is the output of the following code block?
$a = "The quick brown fox jumped over the lazy dog."; $b = array_map("strtoupper", explode(" ", $a)); foreach ($b as $value) { print "$value "; }
ID: 326
What is the output of the following PHP script?
function getName($lastName) { if ($lastName) { return 'Bloggs'; } else { return 'Jeremiah'; } } $func = 'getName'; echo $func(true);
Enter the exact script output
ID: 61
Which of the following functions allows you to stack several error handlers on top of each other?
set_error_handler()
error_handler()
errorHandler()
setError()
ID: 350
The following script is supposed to determine the largest value in an array, however, it may not work correctly. Examine the script and recommend changes if required.
$ages = array(16, 10, 46, 25, 41); $largest = -1; foreach ($ages as $age) { if ($largest < 0) { $largest = $age; break; } if ($age > $largest) { $largest = $age; } } echo sprintf('The largest age is %d', $largest);
ID: 450
What is the output of:
$a = "0"; echo strlen($a); echo empty($a) ? $a : 5; echo $a ?: 5;
ID: 232
Consider the following code snippet:
$hello = 'world'; $world = 'hello'; echo $$$hello;
ID: 74
Consider the following code:
$array = array("a1"=>'x', "a2"=>'e', "a3"=>'z'); asort($array); foreach ($array as $keys => $values) { print "$keys = $values"; }
ID: 163
Consider a scenario in which a website allows users to upload pictures. What kind of security should be set to prevent attacks?
ID: 56
$a = 20 % -8; echo $a;
ID: 100
Consider the following script:
$a = array('a', 'b'); array_push($a, array(1, 2)); print_r($a);
array('a', 'b', 1, 2)
array('a', 'b', array(1, 2))
array(1, 2, 'a', 'b')
array(array(1, 2), 'a', 'b')
ID: 367
$arr1 = ['a' => 'Apple', 'b' => 'Banana']; $arr2 = ['b' => 'Banana', 'a' => 'Australia', 'Apple']; $arr3 = array_diff($arr1, $arr2); $arr4 = array_diff($arr2, $arr1); $keys = array_keys($arr4); echo count($arr3) . ' - ' . $keys[0];
ID: 589
What combination of boolean values for $a, $b, $c, and $d will result in the variable $number being equal to 3?
$a = null; $b = null; $c = null; $d = null; if($a && !$b) { if(!!$c && !$d) { if($d && ($a || $c)) { if(!$d && $b) { $number = 1; } else { $number = 2; } } else { $number = 3; } } else { $number = 4; } } else { $number = 5; }
ID: 420
One way to compare strings in PHP is by using the strcmp() function. This is useful since not only can you determine if two strings are equal, but you can also test if one string is 'greater than' the other (using the corresponding ASCII values in each character comparison). What is the output of the following PHP script?
$test1 = strcmp('hello', "hello"); $test2 = strcmp("Hello", "hello"); $test3 = strcmp('60', '500'); if ($test1 == 0) { echo "a"; } else if ($test1 < 0) { echo "b"; } else { echo "c"; } if ($test2 == 0) { echo "d"; } else if ($test2 < 0) { echo "e"; } else { echo "f"; } if ($test3 == 0) { echo "g"; } else if ($test3 < 0) { echo "h"; } else { echo "i"; }
ID: 515
What would you replace at line 2 // ??? with, below, to make the string 'Hello, World!' be displayed?
function myfunction() { // ??? print $string; } myfunction("Hello, World!");
ID: 783
What is the result of the following code?
class MyCollection { private $coll = []; public function add(?int $x): void { $this->coll[] = $x ?? 0; } public function getElements(): iterable { return $this->coll; } } $collection = new MyCollection(); $collection->add(null); $collection->add(1); $collection->add(0); print_r($collection->getElements());
ID: 106
Which of the following operators will you use to check whether two variables contain the same instance of an object or not?
ID: 11
What does the following function do, when passed two integer values for $p and $q?
function magic($p, $q) { return ($q == 0) ? $p : magic($q, $p % $q); }
ID: 265
Which of the following HTML code snippets can be used for the file uploading?
<form enctype="text/plain" action="index.php" method="post">
<form enctype="plain" action="index.php" method="post">
<form enctype="application/x-www-form-urlencoded" action="index.php" method="post">
<form enctype="multipart/form-data" action="index.php" method="post">
ID: 243
You have been given the following code snippet:
$stmt = $dbh->prepare("SELECT * FROM USER where name = ?"); if ($stmt->execute(array($_GET['name']))) { while (??????) { print_r($row); } }
What will you write at line number 4 to fetch data from database?
$row = $stmt->fetch()
$row = $stmt->getch()
$row = $stmt->fetchall()
$row = $stmt->get()
ID: 33
<?php echo 0x33, ' birds sit on ', 022, ' trees.';
ID: 374
What is the output of the following PHP code?
$myArray = [0, NULL, '', '0', -1]; echo count(array_filter($myArray));
ID: 491
What is the output of the following code?
$s = "This sentence contains many words"; $r = explode(' ', ucfirst($s)); sort($r); echo implode(',', $r);
ID: 148
Which of the following PHP functions will you use as a countermeasure against a cross-site scripting (XSS) attack?
escapeshellcmd()
htmlentities()
mysql_escape_string()
escapeshellarg()
ID: 385
Consider the following PHP script, used to apply a callback function to every element of an array.
function square($val) { return pow($val, 2); } $arr = [1, 2, 3, 4]; /** line **/ $i = 0; foreach ($squares as $value) { if ($i++ > 0) { echo "."; } echo $value; }
What line of code should be substituted with / line / to achieve an output of 1.4.9.16?
$squares = call_user_func_array($arr, 'square');
$squares = call_user_func_array('square', $arr);
$squares = array_map('square', $arr);
$squares = array_walk($arr, 'square');
ID: 545
How do you declare a function to accept a variable (unknown) number of arguments in PHP 7?
function foo(...$parms) {}
function foo(<multi> $parms) {}
function foo($parms <multi>) {}
function foo(@multi $parms) {}
ID: 765
Of the following statements about typehints, which is NOT true?
ID: 175
What is the default timeout of a session cookie?
ID: 689
Considering the code below, which of these statements are true?
ini_set("allow_url_fopen", "1"); $page = file_get_contents("http://www.codepunker.com"); if ($page!=FALSE) { echo "Successfully fetched website contents"; } else { echo "An error has occurred"; }
ID: 653
function byReference(&$variable = 0){ echo ++$variable; } byReference(); byReference();
ID: 701
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]);
ID: 288
Which of the following is an associative array of items uploaded by the current PHP script via the HTTP POST method?
$_COOKIE
$_FILES
$_REQUEST
$_ENV
ID: 570
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.
ID: 806
Which of the following types can be used as an array key? (Select three.)
ID: 305
Which of the following can be used to release the lock applied by the flock() function where fp is a file pointer? Each correct answer represents a complete solution. (Choose two)
flock($fp, LOCK_EX);
flock($fp, LOCK_UN);
flock($fp, LOCK_SH);
fclose($fp);
ID: 553
Which functions would be needed to translate the following string:
I love PHP 5
to the following?
ID: 329
$name = 'Joe'; $$name = 'Bloggs'; echo ${$name};
ID: 759
interface myBaseClass1 { public function doSomething(); public function specialFunction1(); } interface myBaseClass2 { public function doSomething(); public function specialFunction2(); } class myClassA implements myBaseClass1, myBaseClass2 { function doSomething() { echo '...'; } public function specialFunction1(){ echo '...'; } public function specialFunction2(){ echo '...'; } } $a = new myClassA(); $a->doSomething();
ID: 619
The MVC pattern in Web development involves which of the following components?
ID: 246
Which of the following statements describes the use of a GROUP BY clause?
ID: 538
What is the output of the following?
$a = 20; function myfunction($b) { global $a, $c; $a = 30; return $c = ($b + $a); } // 140 = (40 + 30) + 70 print myfunction(40) + $c;
ID: 194
Which function is used to set up start and end element handlers?
xml_get_current_column_number()
xml_get_current_line_number()
xml_parser_create()
xml_set_element_handler()
ID: 623
class MyException extends Exception {} class AnotherException extends MyException {} class Foo { public function something() { throw new AnotherException(); } public function somethingElse() { throw new MyException(); } } $a = new Foo(); try { try { $a->something(); } catch(AnotherException $e) { $a->somethingElse(); } catch(MyException $e) { print "Caught Exception"; } } catch(Exception $e) { print "Didn't catch the Exception!"; }
ID: 773
<?= (function(){ return [$x, $x + 1, $x + 2];})(4)[2];
ID: 356
Is the following code valid, or will it cause a syntax error? Note the missing semi-colon at the end of the statement.
<?= "Hello" ?>
ID: 486
What does the following code output?
$i = function($j) { $i = $j + 4; return $i++; }; $j = 6; echo $i($j);
ID: 565
What should go in the ??????? assignment below to create a Zlib-compressed file foo.gz with a compression level of 9 ?
$file = '????????'; $fr = fopen($file, 'wb9'); fwrite($fr, $data); fclose($fr);
ID: 108
You passed an associative array to the sort() function. What will happen?
ID: 170
Which function is used to get a specific external variable by name and optionally filter it?
filter_input()
filter()
filter_output()
filter_name()
ID: 464
Which of the following is a valid namespace operator in PHP?
ID: 709
How does Opcode Cache improve performance in PHP 5.5+ ?
ID: 532
When an object is serialized, which method will be called, automatically, providing your object with an opportunity to close any resources or otherwise prepare to be serialized?
ID: 720
What is the output of the code below ?
$a = array(0 => "MySQL", 2=>"PHP", 3=>"JAVA", 4 => "JavaScript"); $a = array_values($a); echo $a[1];
ID: 606
How do you define an array in PHP7?
$a = (1, 2, 3);
$a = [1, 2, 3];
$a = array(1, 2, 3);
ID: 533
$dom = new DOMDOcument(); $dom->load('0138.xml'); foreach($dom->documentElement->childNodes as $child) { if(($child->nodeType == XML_ELEMENT_NODE) && $child->nodeName == "item") { foreach($child->childNodes as $item) { if(($item->nodeType == XML_ELEMENT_NODE) && ($item->nodeName == "title")) { print "{$item->firstChild->data}\n"; } } } }
Assuming the referenced XML document exists and matches the parsing logic, what should be displayed when this script is executed?
ID: 426
The sscanf() function is to some extent the opposite of sprintf(), in that it extracts values from a string based on a formatting string. What is the output of the following PHP script?
$str = 'I am 30'; $vals = sscanf($str, '%s %d'); echo trim($vals[0] . ' ' . $vals[1]);
ID: 713
What is the result of the code below?
echo ("0.00") ? "mary" : "angie";
ID: 131
Maria creates an application using PHP script. The application contains certain classes. The class design requires that a particular member variable must be directly accessible to any subclass of this class only. What should Maria do to achieve this?
ID: 693
What is the default value for the "max_execution_time" setting when running PHP as a CLI SAPI ?
ID: 162
Which of the following functions can be used as a countermeasure to a Shell Injection attack? Each correct answer represents a complete solution. Choose all that apply.
mysqli_real_escape_string()
regenerateid()
ID: 50
Which of the following is a magic constant?
$_SERVER
$_POST
__LINE__
$_GET
ID: 343
$myArray = array('a', 'b', 'c'); foreach ($myArray as $k => $v) { echo $v; for ($i = 1; $i < 5; $i++) { if ($i == $k) { break(2); } echo $i; } }
ID: 519
When opening a file in writing mode using the FTP handler, what must be done so that the file will still be written to the server in the event it previously exists?
ID: 116
Which of the following variables are NOT supported by type hinting (PHP < 7)? Each correct answer represents a complete solution. Choose two.
ID: 4
What will be the output when you try to run the script below?
$b = false; if ($b = true) { print("true"); } else { print("false"); }
ID: 171
Which of the following functions wraps a string to a given number of characters?
ID: 196
All of the following are the pre-defined entities except for which one?
ID: 37
What is the output of the following code snippet?
$a = 20; function myfunction($b) { $a = 30; global $a, $c; return $c = ($b + $a); } print myfunction(40) + $c;
ID: 368
Which of the following statements best describes the purpose of PHP's extract() function? This function accepts an array as its first argument.
ID: 211
Which of the following function is used to parse XML data into an array structure?
xml_set_processing_instruction_handler()
xml_set_object()
xml_set_external_entity_ref_handler()
xml_parse_into_struct()
ID: 372
What is the primary difference between array_key_exists() and isset() when checking to see if a given array element exists?
ID: 358
What expression would you pass to error_reporting() if you want all errors and warnings (including "strict" warnings), but not notices (E_NOTICE)?
E_ALL & !E_NOTICE
E_ALL - E_NOTICE
(E_ALL | E_STRICT) & ~E_NOTICE
E_ERROR | E_WARNING | E_STRICT