1h 30m 00s
ID: 670
If you wanted a variable containing the letters A through Z, that allowed you to access each letter independently, which of the following approaches could you use?
ID: 216
Which of the following is used to create an XML parser with namespace support?
xml_get_current_column_number()
xml_parser_create_ns()
xml_get_current_line_number()
xml_get_current_byte_index()
ID: 585
Consider the following PHP string representing an SQL statement:
$query = "UPDATE users SET password='$password' WHERE username='$username'";
Which of the following values for $username or $password would change the behavior of this query when executed?
ID: 259
You want to check whether the header has already been sent or not. Which of the following code segments will you use to accomplish the task?
ID: 766
Which is the correct syntax to define a class constant for the class MyClass?
ID: 791
How does the combined comparison operator ("<=>") work when comparing strings?
ID: 487
What is the output of the following code?
function swings(&$park) { $park++; $park = roundabout($park); } function roundabout($park) { $park *= 2; } $park = 17; echo swings($park);
ID: 765
Of the following statements about typehints, which is NOT true?
ID: 282
What will be the output of the following PHP code?
array_combine([1,2,3], [4,5,6]);
array(1=>2,3=>4,5=>6)
array(1=>4,2=>5,3=>6)
array(1,2,3,4,5,6)
ID: 125
Which of the following methods is called when a user sets a value of an undeclared or undefined attribute of a class?
__get()
__setter()
__set()
__getter()
ID: 61
Which of the following functions allows you to stack several error handlers on top of each other?
setError()
set_error_handler()
errorHandler()
error_handler()
ID: 461
What is the output of this code?
$wish_list = array( 1 => "Romeo and Juliet", 4 => "Bad Science", 2 => "To Kill A Mockingbird" ); print_r(sort($wish_list));
ID: 516
Consider the following code snippet:
$query = "INSERT INTO mytable (myinteger, mydouble, myblob, myvarchar) VALUES (?, ?, ?, ?)"; $statement = mysqli_prepare($link, $query); if (!$statement) { die(mysqli_error($link)); } /* The variables being bound to by MySQLi don't need to exist prior to binding */ mysqli_bind_param($statement, "idbs", $myinteger, $mydouble, $myblob, $myvarchar); /* ???????????? */ /* execute the query, using the variables as defined. */ if (!mysqli_execute($statement)) { die(mysqli_error($link)); }
Assuming this snippet is a smaller part of a correctly written script, what actions must occur in place of the ????? in the above code snippet to insert a row with the following values: 10, 20.2, foo, string ?
ID: 147
Which of the following modes of the fopen() function opens a file in read and write mode and creates one if it does not exist?
ID: 9
Which of the below provided options is correct regarding the below code?
$a = array(1, 2, 3); $b = array(1=> 2, 2 => 3, 0 => 1); $c = array('a' => 1,'b' => 2,'c' => 3); var_dump($a == $b); var_dump($a === $b); var_dump($a == $c);
ID: 341
What is the output of the following PHP script?
for ($i = 5; ; $i++) { if ($i < 10) { break; } } echo $i;
Enter the exact script output
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: 5
Which of the following options is/are correct regarding variable scopes in PHP?
ID: 530
___ can be used to add additional functionality to a stream, such as implementation of a specific protocol on top of a normal PHP stream implementation.
ID: 659
Which function would you use to add an element to the beginning of an array?
$array[0] = "value";
array_shift();
array_unshift();
array_push();
ID: 703
Which of the statements about traits below are true ?
ID: 143
Consider the following PHP code snippet:
class Object { function Object($entity) { $entity->name = "John"; } } class Entity { public $name = "Maria"; } $entity = new Entity(); $obj = new Object($entity); print $entity->name;
What should be the output of this script (Ignore warning)?
ID: 130
You run the following PHP script:
class number { public $a = 1; protected $b = 2; private $c = 3; } $numbers = new number(); foreach($numbers as $value) { echo "$value "; }
What will be the output?
ID: 681
Consider the following script:
$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: 586
What variable reference would go in the spots indcated by ????? in the code segment below?
$msg = "The Quick Brown Foxed Jumped Over the Lazy Dog"; $state = true; $retval = ""; for ($i = 0; (isset(?????)); $i++) { if ($state) { $retval .= strtolower(?????); } else { $retval .= strtoupper(?????); } $state = !$state; } print $retval;
chr($msg);
ord($msg);
$msg{$i}
substr($msg, $i, 2);
ID: 30
Which of the following code can be used to create case insensitive constant?
define("GREETING","How are you today?"); echo constant("greeting");
define("GREETING","How are you today?",FALSE); echo constant("greeting");
define("GREETING","How are you today?",TRUE); echo constant("greeting");
define("GREETING","How are you today?",'USECASE'); echo constant("greeting");
ID: 296
Which of the following functions is used to delete a file?
unset()
unlink()
remove()
delete()
ID: 161
Consider the following PHP script:
<?= "Welcome, {$_POST['name']}.";
What type of attack is possible with this PHP script?
ID: 423
$a = 0.5; $b = 0.1; $c = 16; echo sprintf('%01.2lf %.1lf 0x%x', $a, $b, $c);
ID: 257
Which of the following joins retrieves all rows from one table and only the matching rows from the joined table?
ID: 467
$a = 1; function calculate() { global $a; $a += 7; $a = $a * 043; return --$a; } echo $a;
ID: 489
Which object method is automatically called when an object is cloned?
__wakeup()
__clone()
__copy()
__drone()
ID: 686
When embedding PHP into XML documents, what must you ensure is true in order for things to function properly?
ID: 100
$a = array('a', 'b'); array_push($a, array(1, 2)); print_r($a);
array(array(1, 2), 'a', 'b')
array('a', 'b', array(1, 2))
array('a', 'b', 1, 2)
array(1, 2, 'a', 'b')
ID: 498
How would you change a SimpleXMLElement object into a DOMElement? (choose two)
ID: 578
When writing portable database code using PDO, what is the PDO::ATTR_CASE attribute useful for?
ID: 698
Considering the code below
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 ?
ID: 711
Which is a valid way for calling test function?
function test(?int $n) { var_dump($n); }
test();
test('1');
test(null);
test(1);
ID: 300
Fill in the blank with the appropriate PHP function. The ___ function generates a file resource having 0600 file permission in the file system with a randomly-generated filename to be used as temporary storage. *Exact matching is required.
tempnam()
tempname()
tmp()
temname()
ID: 381
How do you create an array called $arr consisting of a single element with the value 15?
$arr = array_push(15);
$arr = array(15);
$arr = array_shift(15);
$arr = new array(15);
ID: 373
What function is used to remove and return the first element of an array?
array_pop()
array_pull()
array_grab()
array_shift()
ID: 144
Which of the following OOP`s design patterns is used to encapsulate a data source so that accessing data source components becomes hidden within the class that implements the pattern?
ID: 542
function oranges(&$oranges = 17) { $oranges .= 1; } $apples = 5; oranges($apples); echo $apples++;
ID: 488
function print_conditional($x) { if ($x++ == 1) echo "none"; echo "one"; echo "none"; return $x; } $x = 1; print_conditional($x); $x++; print_conditional($x);
ID: 173
Which of the following functions can be used to translate characters or replace substrings?
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: 138
Which of the following is triggered when inaccessible methods are triggered in an object context?
__load()
__call()
__autoload()
__test()
ID: 773
What is the result of the following code?
<?= (function(){ return [$x, $x + 1, $x + 2];})(4)[2];
ID: 73
$base_array = array("red", "green", "yellow", "white"); $replacements_array = array(0 => "orange", 4 => "blue"); $result = array_replace($base_array, $replacements_array); print_r($result);
What will be the output of the script?
Array ( [0] => orange [1] => green [2] => yellow [3] => white [4] => blue )
Array ( [0] => blue [1] => white [2] => yellow [3] => green [4] => orange )
Array ( [0] => yellow [1] => white [2] => blue [3] => green [4] => orange )
ID: 660
What is the output of the following?
function l(&$number) { $number *= 10; return ($number - 5); } $number = 10; $number = L($number); echo $number;
ID: 215
Fill in the blank with the appropriate function name. The _____ function is used to encode a string/array into a json encoded string.
decode()
encode()
json_encode()
json_decode()
ID: 775
What are the main advantages of replacing many fatal errors with Exceptions in PHP 7?
ID: 3
Consider the following code:
$a = 5; $b = 12; $c = 10; $d = 7; $e = ($a * $b) + $c * $d / $a; print($e);
What will be the output of the above code?
ID: 805
What is displayed when the following code is executed?
$a = ['a' => 20, 1 => 36, 40]; array_rand($a); echo $a[0];
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: 179
Which of the following functions can you use to mitigate a command injection attack? Each correct answer represents a complete solution. (Choose two)
escapeshellarg()
htmlentities()
strip_tags()
escapeshellcmd()
ID: 17
Which of the following types of errors halts the execution of a script and cannot be trapped?
ID: 184
What will be the output of the following PHP script?
$dom = new DOMDocument(); $dom->load('book.xml'); $a = $dom->documentElement; print_r($a);
ID: 607
What would go in place of ?????? below to make this script execute without a fatal error?
$a = 1; $b = 0; /* ?????? */ $c = $a / $b;
die();
quit();
exit();
__halt_compiler();
ID: 335
What is the output of the following script?
$number = 100; echo $number < 10 ? "a" : ($number > 100 ? "b" : "c");
ID: 148
Which of the following PHP functions will you use as a countermeasure against a cross-site scripting (XSS) attack?
mysql_escape_string()
ID: 168
Which of the following functions will you use to get the following output of string "Hello world!"?
"!dlrow olleH"
strrev()
stripos()
strrchr()
strops()
ID: 601
What is the best measure one can take to prevent a cross-site request forgery (CSRF)?
ID: 330
How do you check if a variable $name exists in the current scope in a PHP script?
defined($name)
isset($name)
isset('name')
varExists('name')
ID: 616
If you would like to store your session in the database, you would do which of the following?
ID: 203
Which of the following functions will you use to create a new DomElement node? Each correct answer represents a complete solution. Choose three.
DomDocument::createTextNode()
DomNode::cloneNode()
[ ] C)
DomDocument::createElementNS()
ID: 725
What happens when you run the script below ?
define("2MYCONSTANT", "avalue"); if(defined("2MYCONSTANT")) echo "We have a constant: " . 2MYCONSTANT;
ID: 564
What does the following code will print in PHP 7?
$a = [0, 1, 2]; foreach($a as $val) { var_dump(current($a)); }
ID: 76
Which of the following functions is used to insert a new element in the beginning of an array?
array_push()
array_unique()
array_unshift()
ID: 574
Which of the following list of potential data sources should be considered trusted?
ID: 81
What will be the output of the following code snippet?
$array = array(1 => 'one', 3 => '10'); echo $array;
ID: 593
Which of the following are valid PHP variables? (Choose 3)
&$variable
$1variable
${0x0}
@$foo
ID: 8
What will be the output of the following PHP script:
function modifyArray(&$array) { foreach ($array as &$value) { $value = $value + 2; } $value = $value + 3; } $array = array(1, 2, 3); modifyArray($array); print_r($array);
ID: 28
$x = 10; $b = ++$x; print($b);
What will be the value of the variable $b?
ID: 397
Consider the following PHP code, which defines an associative array of fruits and vegetables.
$fruitAndVeg = array( 'c' => 'Carrot', 'p' => 'Tomato', 'b' => 'Banana', 't' => 'Potato', 'a' => 'Apple' ); /** line **/ $keys = array_keys($fruitAndVeg); echo $keys[0];
What line of code should be substituted with / line / to achieve an output of a?
ksort($fruitAndVeg);
keysort($fruitAndVeg);
sort($fruitAndVeg);
usort($fruitAndVeg);