1h 30m 00s
ID: 484
The Active Record design pattern is used for which of the following?
ID: 614
What is the result of the following code snippet?
$array = array( 'a' => 'John', 'b' => 'Coggeshall', 'c' => array( 'd' => 'John', 'e' => 'Smith' ) ); function something($array) { extract($array); return $c['e']; } print something($array);
ID: 224
What will be the output of the following code snippet?
$string = '133445abcdef'; $mask = '12345'; echo strspn ($string, $mask);
ID: 696
When working with unfamiliar code, what is the best way to find out in which file a class is defined ?
# Using the grep command to search through the application files: $out = array(); exec("grep -r 'Classname' .", $out); var_dump($out);
# Using the get_declared_classes() function: $classes = get_declared_classes(); var_dump($classes);
# Using ReflectionClass: $reflection = new ReflectionClass('ClassName'); echo $reflection->getFileName();
ID: 722
Considering the table structure below what MySQL query will load a result set containing all students names enrolled in the programming classes ?
--students table: | studentid | name | -------------------- | 1 | Mike | | 2 | John | | 3 | Jeff | | 4 | Anne | --classes table: | classid | classname ------------------------- | 1 | Math | 2 | Programming | 3 | Biology classes_to_students table: | studentid | classid ------------------------- | 1 | 1 | 2 | 2 | 3 | 2 | 4 | 3
SELECT s.name FROM students as s INNER JOIN classes_to_students as cs ON s.studentid = cs.studentid INNER JOIN classes as c ON c.classid = cs.classid WHERE c.classname='Programming';
SELECT s.name FROM students as s WHERE s.studentid IN ( SELECT studentid FROM classes_to_students as cs INNER JOIN classes as c ON cs.classid = c.classid WHERE c.classname = 'Programming' );
-- none
SELECT s.name FROM students as s INNER JOIN classes as c ON s.studentid = c.classid INNER JOIN classes_to_students as cs ON s.studentid = cs.studentid WHERE c.classname = 'Programming';
ID: 716
What is wrong in the following code (assume that $db is an instance of mysqli, mytable exists and has a column called student):
$sql = "SELECT student FROM mytable WHERE student = '$_POST["student"]'"; if ($result = $db->query($sql)) { while($row = $result->fetch_object()) echo $row->student; }
ID: 454
What will the output of the following code be?
$a = range(3,9); foreach ($a as $b) { switch($b) { case 3: $b = 7; case 7: $b = 3; default: // do nothing } } echo implode('-',$a);
ID: 41
What is the value of $x in the following code snippet?
$x = 123 == 0123;
ID: 98
You have been given the following PHP script:
$a = 'somevalue'; $array = ["a" => "One", "b" => "Two", "c" => "Three"]; // ???? echo "\$a = $a; \$b = $b; \$c = $c;";
What should you write at line number 3 to get the following output? $a = One; $b =Two; $c = $Three;
ksort($array);
implode($array);
asort($array);
extract($array);
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: 806
Which of the following types can be used as an array key? (Select three.)
ID: 547
What is the output of the following?
function a(&$apples) { $apples++; } $oranges = 5; $apples = 5; a($oranges); echo "I have $apples apples and $oranges oranges";
ID: 182
Which of the following functions in SimpleXML can be used to return an iterator containing a list of all subnodes of the current node?
attributes()
asXML()
children()
getName()
ID: 38
Which of the following PHP variable names is not a valid variable name?
$var
$_2var
$2var
$__var
ID: 419
What is the output of the following PHP script?
echo strcmp(5678, '5678');
ID: 291
Fill in the blank with the appropriate function(). The ___ function is used to copy data from one stream to another. It is mainly useful in copying data between two open files. *Matching is case-insensitive.
ID: 229
Consider a string in the following format:
a*bcd/a.d
You want to perform regular expression in this string; however, you are unable to do this since the string contains special characters. You can make this string PCRE compatible if you convert this string in the following format:
explode()
preg_match()
preg_quote()
preg_split()
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()
escapeshellarg()
regenerateid()
escapeshellcmd()
ID: 266
Fill in the blank with the appropriate function name. The __ function is used to encode a URL. *Matching is case-insensitive.
ID: 686
When embedding PHP into XML documents, what must you ensure is true in order for things to function properly?
ID: 318
$a = 25; echo $a % 10;
ID: 292
You run the following PHP script:
<?= gethostbyaddr($_SERVER['REMOTE_ADDR']);
What will be the output of the script?
ID: 288
Which of the following is an associative array of items uploaded by the current PHP script via the HTTP POST method?
$_ENV
$_COOKIE
$_REQUEST
$_FILES
ID: 773
What is the result of the following code?
<?= (function(){ return [$x, $x + 1, $x + 2];})(4)[2];
ID: 23
Fred works as a Web developer in Fastech Inc. He writes the following script:
$s = 2; switch ($s) { case 1: print("Fred"); break; case 2: print("Fast"); case 3: print("Tech"); default: print("default"); }
What will be displayed as output when Fred attempts to run this PHP script?
ID: 786
What is displayed when the following code is executed?
function a(): void { echo 'Hello'; } function b(): void { echo 'World'; return void; } a(); b();
ID: 138
Which of the following is triggered when inaccessible methods are triggered in an object context?
__autoload()
__load()
__test()
__call()
ID: 332
define('123MESSAGE', '123'); if (strlen(123MESSAGE) == 12) { echo 123MESSAGE; } else { echo 'ABC'; }
ID: 327
$myVar = 'foo'; $$myVar = 'bar'; echo ${'myVar'} . $foo;
ID: 780
Can anonymous classes have constructors?
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: 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: 241
Fill in the blank with the appropriate term. The ____ function is used to reverse a given string. *Matching is case-insensitive.
strrev
strstr
strtr
strtok
ID: 465
What is the output of the following code?
function print_conditional() { static $x; if ($x++ == 1) echo "many"; echo "good"; echo "things"; return $x; } $x = 1; print_conditional(); $x++; print_conditional();
ID: 119
Which of the following access controls specifies that a feature can be accessed by any other class?
ID: 762
Which of the following statements about autoloading is true?
ID: 764
Reflection functions CANNOT do:
ID: 631
Consider the following simple PHP script:
$dom = new DomDocument(); $dom->load('test.xml'); $xpath = new DomXPath($dom); $nodes = $xpath->query(???????, $dom->documentElement); echo $nodes->item(0)->getAttributeNode('bgcolor')->value . "\n";
What XPath query should go in the ?????? above to display the "bgcolor" attribute of the first "body" node in the XML document?
ID: 546
function a($number) { return (b($number) * $number); } function b(&$number) { return ++$number; } echo a(5);
ID: 692
What is the output of the following script ?
function generate() { for ($i = 1; $i <= 3; $i++) { yield $i; } } $generator = generate(); if (is_array($generator)) { echo "Is Array"; } elseif(is_object($generator)) { echo "Is Object"; } else { echo "Is none of the above"; }
ID: 68
You run the following script:
<?php $a = 5 < 2; echo (gettype($a));
What will be the output?
ID: 181
Which of the following is used to retrieve the namespaces used in an XML document from a SimpleXMLElement object?
getElement()
getNamespaces()
getDefined()
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.
$_POST
$_GET
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?
keysort($fruitAndVeg);
sort($fruitAndVeg);
ksort($fruitAndVeg);
usort($fruitAndVeg);
ID: 83
Which of the following is the correct naming convention of user defined functions?
&sum($var1, $var2)
123_sum($var1,$var2)
^^_sum($var1, $var2)
_sum($var1, $var2)
ID: 590
One can ensure that headers can always be sent from a PHP script by doing what?
ID: 443
$a = "a, b,c, d, e f, g"; $b = array_merge(explode(', ', $a), array("a", "b")); echo count($b);
ID: 630
When comparing two strings, which of the following is acceptable?
$a == $b;
strcasecmp($a, $b);
$a === $b;
strcmp($a, $b);
ID: 456
What is the output of this code:
function c($a, $b = 1, $c) { return array($c, $a, $b); } list($a, $b, $c) = c(0,0,0); echo $b;
ID: 513
Which of the following functions are used with the internal array pointer to accomplish an action?
ID: 742
$str = 'abcdef'; if (strpos($str, 'a')) { echo "Found the letter 'a'"; } else { echo "Could not find the letter 'a'"; }
ID: 663
What is the best way to ensure that a user-defined function is always passed an object as its single parameter?
ID: 112
What will be the result of comparing the following two PHP arrays?
$x = array(10,2,4); $y = array(1 => 2, 0 => 10, 2 => 4); var_dump($x == $y);
ID: 140
What is the output of this code snippet?
$a = [0.001 => 'b', .1 => 'c']; print_r($a);
ID: 223
You want to fetch the top level domain (com) from the email Which of the following functions will you use to accomplish the task?
eregi("john@ucertify.com", ".");
substr("john@ucertify.com", strpos("john@ucertify.com", ".")+1);
substr("john@ucertify.com", strpos("john@ucertify.com", "."));
eregi("^[a-z0-9\._-]+"."@"."([a-z0-9][a-z0-9-]*[a-z0-9]\.)+"."([a-z]+\.)?"."([a-z]+)$", 'john@ucertify.com'));
ID: 690
What output will this code produce ?
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;
ID: 739
What is goog rule to follow when quoting string data?
ID: 438
$pattern = '/[a-z]{4} /'; $string = 'Mary had a little lamb'; $matches = preg_match($pattern, $string); print_r($matches);
ID: 502
Session fixation - a commonly-used session-based attack - can be prevented simply by giving a user a new session ID whenever they obtain a new level of permission on a site (for instance, after they successfully login). Which PHP function is used to change the ID for an active session?
ID: 287
You want to enable compression in the PHP code output. Which of the following ways should you prefer most?
ID: 262
Which of the following recovers the committed transaction updates against any kind of system failure?
ID: 457
What is the output of the following code:
function a($a) { echo $a . "&"; } function b($a) { echo "-" . $a; } $a = "!"; $b = &$a; echo a(b($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: 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: 158
Which of the following are the countermeasures of the remote code injection? Each correct answer represents a complete solution. Choose all that apply.
ID: 676
function myfunction($b) { $a = 30; global $a, $c; return $c = ($b + $a); } print myfunction(40) + $c;
ID: 273
The dl() function is used to load PHP extensions on the server at runtime. However, you want to disable it due to some security issue. Which of the following actions will you perform to accomplish the task?
ID: 499
What is the preferred way of writing the value 25 to a session variable called age?
$_SESSION['age'] = 25;
$HTTP_SESSION_VARS['age'] = 25;
session_register('age', 25);
$age = 25; session_regiser('age');
ID: 468
function format(&$item) { $item = strtoupper($item) . '.'; return $item; } $shopping = array("fish", "bread", "eggs", "jelly", "apples"); array_walk($shopping, "format"); $shopping = sort($shopping); echo $shopping[1];
ID: 708
What is the best way to store and verify passwords in PHP ?
ID: 80
$array1 = array("a", "b", "c", "d", "e", "f"); $array2 = array_slice($array1, -3); foreach($array2 as $val) { print "$val "; }
ID: 541
How can the following code be re-written from PHP 4 to PHP 5/7?
if (get_class($myObj) == "MyClass") { // Do something }
if(get_class($myObj) == "MyClass")
if(strtolower(get_class($myObj)) == "myclass")
if($myObj implements MyClass)
if($myObj instanceof MyClass)
ID: 161
Consider the following PHP script:
<?= "Welcome, {$_POST['name']}.";
What type of attack is possible with this PHP script?
ID: 534
When is it acceptable to store sensitive information in an HTTP cookie?
ID: 551
When connecting to a database using PDO, what must be done to ensure that database credentials are not compromised if the connection were to fail?