1h 30m 00s
ID: 107
You have been given the following PHP code snippet:
$array = array('1', '2', '3'); foreach($array as $key => $value) { $value = 4; } print_r($array);
What will be the output?
Array ( [0] => 4 [1] => 8 [2] => 12 )
# The script will throw an error message.
Array ( [0] => 1 [1] => 2 [2] => 3 )
Array ( [0] => 1 [4] => 2 [8] => 3 )
ID: 569
Consider the following script:
$string = "<b>I like 'PHP' & I think it is \"cool\"</b>"; var_dump(htmlentities($string, ENT_QUOTES)); var_dump(htmlspecialchars($string));
In this script, do the two var_dump() calls produce the same string? Why or Why Not?
ID: 304
Which of the following functions will you use to copy data between two opened files?
ID: 770
Which class of HTTP status code is used for error conditions?
ID: 632
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();
ID: 404
What is the PHP function used to determine the length of a string?
length()
size()
count()
strlen()
ID: 378
How do you determine the number of elements in array?
ID: 649
Which of the following cases are cases when you should use transactions?
ID: 255
You have to select persons whose age is between twenty-five and forty from a database named HumanResource. Which of the following criteria will you use in the query to accomplish the task?
ID: 645
When migrating the following code from PHP 4 to PHP 5, what should be changed?
class MyClass { function MyClass($param) { # Do something with $param $this->_doSomething($param); } // Private method to MyClass function _doSomething($param) { # Do something with $param } } class AnotherClass extends MyClass { var $param = "foo"; function AnotherClass() { parent::MyClass($this->param); } }
ID: 694
What happens when the code below is executed ?
class foo { private $variable; function __construct() { $this->variable = 1; } function __get($name) { return $this->$name; } } $a = new foo; echo $a->variable;
ID: 281
Which of the following superglobals can you use to fetch a cookie from the client's side? Each correct answer represents a complete solution. Choose all that apply.
$_GET
$_POST
$_REQUEST
$_COOKIE
ID: 580
What does the following code print?
echo 2 <=> 1;
ID: 429
Given the following PHP code, what value must be assigned to $format so each digit is extracted individually in the call to sscanf()?
$str = '31337'; $format = '???'; $digits = sscanf($str, $format); var_dump($digits);
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: 210
Which of the following retrieves the child nodes of a specified XML node?
getNamespaces()
children()
getDocNamespaces()
getName()
ID: 236
You want to parse the following string in PHP:
$some_string="Student\tJohn\nMichel\tMaria";
Which of the following PHP functions will you use to parse the string according to the \t and \n characters?
strrev()
strtr()
strtok()
substr()
ID: 72
What will be the output of the following code snippet?
$a = 1; $b = 2; $c = 0xAF; $d = $b + $c; $e = $d * $b; $f = ($d + $e) % $a; print($f + $e);
ID: 402
The str_pad() function is used pad a string to a given length using another string. What is the output of the following PHP script?
$number = 5; $len = 3; $pad = '0'; echo str_pad($number, $len, $pad, STR_PAD_LEFT);
ID: 283
You have the following code in the welcome.html file:
<form action="welcome.php" method="post"> Your Name: <input type="text" name="fname" /> Your Girl Friend Name: <input type="text" name="fname" /> <input type="submit" /> </form>
The PHP code of the welcome.php file is as follows:
ID: 711
Which is a valid way for calling test function?
function test(?int $n) { var_dump($n); }
test(1);
test(null);
test();
test('1');
ID: 646
Which of the following functions is used to determine if a given stream is blocking or not?
ID: 218
What are possible value of the following code, if $a and $b variable are defined in current scope script?
echo ($a <=> $b);
ID: 790
Give the following function signature:
function a(): iterable { // }
What actual data types are acceptable for this function to return?
ID: 377
Which of the following statements best describes what happens to an array when array_shift() is called on it?
ID: 202
You have given the following XML data in the tasks.XML file:
<?xml version="1.0" encoding="ISO-8859-1" ?> <tasklist> <note> <tasks>Validate data</tasks> <details>String Validation</details> </note> <note> <tasks>Secure data</tasks> <details>Encryption</details> </note> </tasklist>
Now, you run the following PHP script:
ID: 244
A table named employees is given below:
Which of the following statements would return the employees' names, in ascending order, based on their last name and first name?
ID: 194
Which function is used to set up start and end element handlers?
xml_get_current_line_number()
xml_get_current_column_number()
xml_set_element_handler()
xml_parser_create()
ID: 75
What will be the output of the following PHP code?
array_combine(array(1,2,3,6), array(4,5,6));
ID: 525
What is the best way to ensure the distinction between filtered / trusted and unfiltered / untrusted data?
ID: 445
Which of the following functions would be a valid way to create an array containing items from three existing arrays?
array_splice()
array_merge()
array_combine()
array_keys()
ID: 66
Which of the following will you use to iterate a PHP associative array?
ID: 87
You want to create an anonymous function in the middle of a script that will return the square of a given number. Which of the following PHP scripts can you use to accomplish the task?
Each correct answer represents a complete solution. (Choose two)
$foo = create_function('$x', 'return $x*$x;'); echo $foo(10);
$foo = create_function("\$x", "return \$x*\$x;"); echo $foo(10);
$foo = create_function("$x", "return $x*$x;"); echo $foo(10);
$foo = create_function("$x", "$x*$x;"); echo $foo(10);
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: 507
What is the correct way to add 1 to the $count variable?
$count
<?php count++
<?php $count += 1;
<?php ++count
<?php $count++;
ID: 394
Remembering that keys are not reset when using natsort(), what is the output of the following PHP script?
$filenames = array( 'img12.png', 'img7.png', 'img21.png', 'img1.png' ); natsort($filenames); $values = array_values($filenames); echo $values[1];
Enter the exact script output
ID: 571
When working with SimpleXML in PHP 5, the four basic rules on how the XML document is accessed are which of the following?
ID: 730
What is the output of the script below ?
$i = 1; do { $i++; } while ($i===0); echo $i;
ID: 430
What is the output of the following:
$m = 3; $n = 0; function l() { $m = 0; $m++; global $n; return array($n,$m); } echo implode((L(l())),',');
ID: 290
Which of the following functions can be used to get whether or not a file is readable?
is_readable()
touch()
fseek()
stat()
ID: 272
Which of the following header codes is used for redirection?
ID: 258
Which of the following joins will you use to display data that do not have an exact match in the column?
ID: 222
Which of the following functions will you use to get the output from the string ? Each correct answer represents a complete solution. Choose all that apply.
ID: 599
Which of the following functions allow you to introspect the call stack during execution of a PHP script?
ID: 686
When embedding PHP into XML documents, what must you ensure is true in order for things to function properly?
ID: 523
Consider the following code:
session_start(); if(!empty($_REQUEST['id']) && !empty($_REQUEST['quantity'])) { $id = scrub_id($_REQUEST['id']); $quantity = scrub_quantity($_REQUEST['quantity']) $_SESSION['cart'][] = array('id' => $id, 'quantity' => $quantity) } /* .... */
What potential security hole would this code snippet produce?
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: 431
What would be output when the following code is run?
class M { function m() { echo "M"; } function construct() { echo "mmm"; } } $m = new M(); $m->m();
ID: 407
What is the output of the following PHP script?
$foo = 'bar'; echo '$foo\'' . "$foo\'";
ID: 572
How do you declare the return type of a function?
function sum($a, $b) => int {return $a + $b;}
function sum($a, $b) {return (int)$a + $b;}
function sum($a, $b) :int {return $a + $b;}
ID: 55
Which of the following is NOT a valid PHP variable name?
$$a
$a
$_a
$1a
ID: 153
John works as a professional ethical hacker. He has been assigned the project of testing the security of www.we-are-secure.com. On the We-are-secure login page, he enters ='or''=' as a username and successfully logs in to the user page of the Web site. To which of the following attacks is the We-are-secure login page vulnerable?
ID: 125
Which of the following methods is called when a user sets a value of an undeclared or undefined attribute of a class?
__set()
__getter()
__setter()
__get()
ID: 408
$str = 'val1,val2,,val4,'; echo count(explode(',', $str));
ID: 261
Which of the following are the limitations of the prepared statements? Each correct answer represents a complete solution. Choose all that apply.
ID: 278
<form method=get> <select name ="fruits" id="fruits"> <option value="1">Apple</option> <option>Orange</option> <option value="3">Strawberry</option> </select> <input type="submit" value="Submit"> <?= $_GET['fruits'] ?? ''; ?>
What will be the output if you select 'Orange' from the dropdown menu?
ID: 115
Which of the following allows a programmer to set a string value for the object that will be used if the object is ever used as a string?
__string()
__call()
__toString()
ID: 260
You are using a database named SalesDB to keep all sales records. The SalesDB database contains a table named Orders. You are required to create a new table named OldOrders and transfer all the data from the Orders table to the new table. Which of the following statements will you use to accomplish the task?
ADD INTO
IMPORT INTO
SELECT INTO
INSERT INTO
ID: 90
Consider the following PHP script:
$a = 5; $b = 10; function Mul() { $GLOBALS['b'] = $GLOBALS['a'] * $GLOBALS['b']; } Mul(); print($b);
ID: 746
What is the output of the following code?
$a = array(1, 2, 3); foreach( $a as $x) { $x *= 2 } echo $a[0] * $a[1] * $a[2];
ID: 192
Which of the following functions can you use to add data? Each correct answer represents a complete solution. Choose all that apply.
DomNode::insertBefore()
DomNode::appendChild()
DomElement::setAttribute()
DomNode::cloneNode()
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: 545
How do you declare a function to accept a variable (unknown) number of arguments in PHP 7?
function foo($parms <multi>) {}
function foo(@multi $parms) {}
function foo(<multi> $parms) {}
function foo(...$parms) {}
ID: 805
What is displayed when the following code is executed?
$a = ['a' => 20, 1 => 36, 40]; array_rand($a); echo $a[0];
ID: 452
Which of the following are valid constant names? (Choose three)
ID: 336
$arr = array(1, 2, 3, 4); foreach ($arr as $value) { $value -= 1; } foreach ($arr as &$value) { $value *= 2; } foreach ($arr as $v) { if ($v <= 8) { echo $v; } }
ID: 81
$array = array(1 => 'one', 3 => '10'); echo $array;
ID: 241
Fill in the blank with the appropriate term. The ____ function is used to reverse a given string. *Matching is case-insensitive.
strtr
strrev
strstr
strtok
ID: 494
Which function would transform the string "excellent PHP functions" into the string "Excellent PHP Functions"?
ID: 64
You run the following script:
10 = $a; echo $a;
ID: 636
When using a function such as strip_tags, are markup-based attacks still possible?
HTML tag is a security risk
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: 607
What would go in place of ?????? below to make this script execute without a fatal error?
$a = 1; $b = 0; /* ?????? */ $c = $a / $b;
__halt_compiler();
die();
exit();
quit();
ID: 370
What line should be added to the cleanArray() function below to ensure this script outputs 1525hello?
function cleanArray($arr) { $functions = array(); /** line **/ $ret = $arr; foreach ($functions as $func) { $ret = $func($ret); } return $ret; } $values = [15, '', 0, 25, 'hello', 15]; foreach (cleanArray($values) as $v) { echo $v; }
$arr = array_clean($arr);
array_push($functions, 'array_reduce');
array_push($functions, 'array_filter', 'array_unique');
array_pop($functions, 'array_clean');
ID: 298
Which of the following file functions can be used to indicate the current position of the file read/write pointer?
ftell()
feof()
fread()