Main Snake Zend Zend Questions Exam Quicktest MZend

1h 30m 00s


Question: 1 (ID:510)

ID: 510


Consider the following String:


                        
$string = "John\tMark\nTed\tLarry";                    

Which of the following functions would best parse the string above by the tab (\t) and newline (\n) characters?



Question: 2 (ID:76)

ID: 76


Which of the following functions is used to insert a new element in the beginning of an array?





Question: 3 (ID:664)

ID: 664


Consider the following PHP script fragment:


                        
$title = $dom->createElement('title');
$node = ?????

$title->appendChild($node);
$head->appendChild($title);                    

What should ????? be replaced with to add a <title> node with the value of Hello, World!



Question: 4 (ID:400)

ID: 400


The following script defines a function called buildUrl(), which is intended to be a crude way of normalizing URLs. What line of code must be inserted into buildUrl() to ensure $url1 and code $url2 are both equal to http://phpriot.com/quiz/?


                        
function buildUrl($domain, $path) {
    // insert line of code here
    return $ret;
}

$domain1 = 'http://phpriot.com/';
$domain2 = 'http://phpriot.com';
$path    = '/quiz/';

$url1 = buildUrl($domain1, $path);
$url2 = buildUrl($domain2, $path);                    



Question: 5 (ID:352)

ID: 352


What is the output of the following script?


                        
$number = 25;
if ($number <= 25) {
    echo "lte";
} else if ($number == 25) {
    echo "e";
} else if ($number >= 25) {
    echo "gte";
} else {
    echo "o";
}                    

Enter the exact script output



Question: 6 (ID:420)

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"; }                    

Enter the exact script output



Question: 7 (ID:138)

ID: 138


Which of the following is triggered when inaccessible methods are triggered in an object context?





Question: 8 (ID:803)

ID: 803


What is the best way to test if $param is an anonymous function in a method?





Question: 9 (ID:366)

ID: 366


The array_search() function is used to determine the array key for a given value. If the value is not found then false is returned. What is the output of the following PHP script?


                        
$values = [15, 12, "15", 34, 15 => 25];
$key = array_search("15", $values);
if  (!$key)  {
    echo "Not found";
} else {
    // gettype() will return either 'string' or 'integer'
    echo $key . ' - ' . strtolower(gettype($values[$key]));
}                    



Question: 10 (ID:104)

ID: 104


What will be the output of the following PHP script?


                        
$array = [
    'a' => 'One', 
    'b' => 'Two', 
    'c' => [
        'd' => 'Three', 
        'e' => 'Four'
   ]
];
function print_element($array) {
    extract($array);
    return $c['e'];
 }
 print print_element($array);                    



Question: 11 (ID:404)

ID: 404


What is the PHP function used to determine the length of a string?





Question: 12 (ID:621)

ID: 621


Consider the following code snippet:


                        
$link = mysqli_connect("hostname", "username", "password");
if (!$link) {
    /* $error = ??????; */
    die("Could not connect to the database: $error");
}                    

What would go in place of the ???? above for this script to function properly?



Question: 13 (ID:97)

ID: 97


Which of the following statements will return the second parameter passed to a function?





Question: 14 (ID:342)

ID: 342


What is the output of the following script?


                        
$x = 5;
switch ($x) {
    case 5:
        echo "a";
        break;
    case 10:
        echo "b";
        break;
    case 15:
        echo "c";
        break;
    case 20:
        echo "d";
        break;
    case default:
        echo "e";
}                    



Question: 15 (ID:513)

ID: 513


Which of the following functions are used with the internal array pointer to accomplish an action?





Question: 16 (ID:186)

ID: 186


Which of the following is used to retrieve the root element from an XML file?





Question: 17 (ID:493)

ID: 493


Which of the following is a magic method in PHP?





Question: 18 (ID:652)

ID: 652


What should go in the missing line ????? below to produce the output shown?


                        
$array_one = array(1,2,3,4,5);
$array_two = array('A', 'B', 'C', 'D', 'E');
/* ????? */ 
print_r($array_three);    
/* Result:   
    Array
    (
        [5] => A
        [4] => B
        [3] => C
        [2] => D
        [1] => E
    )
*/                    



Question: 19 (ID:326)

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



Question: 20 (ID:485)

ID: 485


With a single existing cookie set for this domain with the key "theme" and the value "green", what does the following code output?


                        
print_r($_COOKIE);
setcookie('theme', NULL, time() - 3600);
print_r($_COOKIE);
unset($_COOKIE);
print_r($_COOKIE);                    



Question: 21 (ID:107)

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?



Question: 22 (ID:518)

ID: 518


In PHP the error control operator is ___





Question: 23 (ID:419)

ID: 419


What is the output of the following PHP script?


                        
echo strcmp(5678, '5678');                     



Question: 24 (ID:801)

ID: 801


What is the ouput of the following code?


                        
class Magic {
    public $a = "A";
    protected $b = ["a" => "A", "b" => "B", "c" => "C"];
    protected $c = [1, 2, 3];

    public function __get($v)
    {
        echo "$v,";
        return $this->b[$v];
    }

    public function __set($var, $val)
    {
        echo "$var: $val,";
        return $this->$var = $val;
    }
}

$m = new Magic();
echo $m->a . "," . $m->b . "," . $m->c . ",";
$m->c = "CC";
echo $m->a . "," . $m->b . "," . $m->c;                    



Question: 25 (ID:777)

ID: 777


What will happen when the following code is executed?


                        
interface Additionable {
    public function add($x, $y);
}

function average ($a, $b) {
    $anon = new class implements Additionable {
        public function divide($x, $y) {
            return $x / $y;
        }
        public function add($x, $y) {
            return $x + $y;
        }
    };

    $sum = $anon->add($a, $b);
    $average = $anon->divide($sum, 2);
    return $average;
}
echo average(10, 70);                    



Question: 26 (ID:233)

ID: 233


Which of the following metacharacters can be used to find a non-word character?





Question: 27 (ID:152)

ID: 152


Which of the following directives can be used to improve the security while using the shared hosting environment? Each correct answer represents a complete solution. Choose all that apply.





Question: 28 (ID:611)

ID: 611


Which of the following functions could be used to break a string into an array?





Question: 29 (ID:113)

ID: 113


Which of the following keywords is used to prevent a method/class to be overridden by a subclass?





Question: 30 (ID:598)

ID: 598


If you would like to change the session ID generation function, which of the following is the best approach for PHP 5?





Question: 31 (ID:284)

ID: 284


Which of the following statements is true about deleting a client's cookie?





Question: 32 (ID:316)

ID: 316


Consider the use of bitwise operators on hexadecimal values. What is the output of the following PHP script?


                        
$a = 0xF0;
$b = 0x0F;

$val1 = $a & $b; // bitwise AND
$val2 = $a | $b; // bitwise OR
$val3 = $a ^ ($b | $a); // bitwise XOR

echo sprintf('0x%02X - 0x%02X - 0x%02X', $val1, $val2, $val3);                    



Question: 33 (ID:624)

ID: 624


A fingerprint of a string can be determined using which of the following?





Question: 34 (ID:159)

ID: 159


You want to stop showing PHP errors or to show only critical errors so that a malicious hacker cannot hack your Website. Which of the following PHP directive settings will you use to accomplish this task? Each correct answer represents a part of the solution. Choose all that apply.





Question: 35 (ID:716)

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;
}                    



Question: 36 (ID:443)

ID: 443


What is the output of the following code?


                        
$a = "a, b,c, d, e f, g";
$b = array_merge(explode(', ', $a), array("a", "b"));
echo count($b);                    



Question: 37 (ID:732)

ID: 732


What is the output of the following code?


                        
$a = 1;
++$a;
$a *= $a;
echo $a--;                    



Question: 38 (ID:433)

ID: 433


What is the output of the following line of code:


                        
$a = 4 << 2 + 1;
echo $a;                    



Question: 39 (ID:349)

ID: 349


What is the output of the following PHP script?


                        
for ($i = 0; $i < 3; $i++) {
    for ($j = 3; $j > 0; $j--) {
        if ($i == $j) {
            break;
        }
        echo $j;
    }
}                    



Question: 40 (ID:343)

ID: 343


What is the output of the following PHP script?


                        
$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;
    }
}                    

Enter the exact script output



Question: 41 (ID:576)

ID: 576


Given the following array:


                        
$array = array(1,1,2,3,4,4,5,6,6,6,6,3,2,2,2);                    

The fastest way to determine the total number a particular value appears in the array is to use which function?



Question: 42 (ID:718)

ID: 718


How do you obtain the length of a string in PHP ?





Question: 43 (ID:553)

ID: 553


Which functions would be needed to translate the following string:


                        
I love PHP 5
                    

to the following?



Question: 44 (ID:445)

ID: 445


Which of the following functions would be a valid way to create an array containing items from three existing arrays?





Question: 45 (ID:359)

ID: 359


This question tests your knowledge of boolean values and casting. What is the output of the following PHP script.


                        
$myInt = -1;
$myBool = (bool) $myInt;
if ($myBool > 0) {
    echo "5";
} else if ($myBool == true) {
    echo "6";
} else if (!$myBool) {
    echo "7";
} else {
    echo sprintf("%d", $myBool);
}                    

Enter the exact script output



Question: 46 (ID:449)

ID: 449


Is the following valid PHP code?


                        
<php>
echo 'There's a worm in my apple';
</php>                    



Question: 47 (ID:282)

ID: 282


What will be the output of the following PHP code?


                        
array_combine([1,2,3], [4,5,6]);                    



Question: 48 (ID:293)

ID: 293


Which of the following statements is true about __FILE__ constant?





Question: 49 (ID:694)

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;                    



Question: 50 (ID:800)

ID: 800


Which of the following statements about exceptions is NOT true?





Question: 51 (ID:550)

ID: 550


The following code snippet displays what for the resultant array?


                        
$a = array(1 => 0, 3 => 2, 4 => 6);
$b = array(3 => 1, 4 => 3, 6 => 4);    
print_r(array_intersect($a, $b));                    



Question: 52 (ID:570)

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.





Question: 53 (ID:308)

ID: 308


What is the output of the following PHP script:


                        
$a = 10;
$b = 20;
$c = 30;
echo ($a < 50 && $b > 100 || $c == 30) ? "a" : "b";
echo ($b < 50 XOR $c == 30) ? "c" : "d";                    

Enter the exact script output



Question: 54 (ID:6)

ID: 6


You run the following PHP script:


                        
for($x = 1; $x <= 2; $x++) {
      for($y = 1; $y <= 3; $y++) {
         if ($x == $y) continue; 
         print("x = $x  y =  $y");
      }
}
                    

What will be the output? Each correct answer represents a complete solution. Choose all that apply.



Question: 55 (ID:759)

ID: 759


What is the output of the following code?


                        
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();                    



Question: 56 (ID:189)

ID: 189


Which of the following is used to retrieve the namespaces declared in an XML document from a SimpleXMLElement object?





Question: 57 (ID:123)

ID: 123


In which of the following situations will you use the set_exception_handler() function?





Question: 58 (ID:82)

ID: 82


What will be the output of the following PHP code snippet?


                        
$array = array(1.1 => '1', 1.2 => '1');
echo count($array);                    



Question: 59 (ID:409)

ID: 409


What is the PHP function used to make a string all upper-case?





Question: 60 (ID:551)

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?





Question: 61 (ID:172)

ID: 172


Consider the PHP program (which includes a file specified by request):


                        
<?php
$color = 'blue';
if (isset( $_GET['COLOR'] ) )
       $color = $_GET['COLOR'];
require( $color . '.php' );
?>
<form method="get">
     <select name="COLOR">
        <option value="red">red</option>
        <option value="blue">blue</option>
     </select>
     <input type="submit">
</form>                    

A malicious user injects the following command:



Question: 62 (ID:511)

ID: 511


What is the output of?


                        
function apple($apples = 4) {
    $apples = $apples / 2;
    return $apples;
}    
$apples = 10;
apple($apples);
echo $apples;                    



Question: 63 (ID:100)

ID: 100


Consider the following script:


                        
$a = array('a', 'b'); 
array_push($a, array(1, 2)); 
print_r($a);                    

What will be the output?



Question: 64 (ID:544)

ID: 544


Removing undesired markup tags from input can best be done using which function?





Question: 65 (ID:27)

ID: 27


What is the result of the following code?


                        
$sentence = ['John', 'Doe', 'has', 'a', 'car'];

for ($i = 0; $i < count($sentence); $i++) {
    echo (function() use ($sentence) {
        return $sentence;
    })()[$i][0];
}                    



Question: 66 (ID:465)

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();                    



Question: 67 (ID:271)

ID: 271


You want to enable compression for every Web page of your Website. Which of the following PHP.ini directives can you set to accomplish the task? Each correct answer represents a complete solution. Choose all that apply.





Question: 68 (ID:259)

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?





Question: 69 (ID:618)

ID: 618


What is the output of the following?


                        
function _1dotEach($n) {
    if ($n > 0) {
        _1dotEach(--$n);
        echo ".";
    } else {
        return $n;
    }
}
_1dotEach(4);                    



Question: 70 (ID:617)

ID: 617


When writing CLI scripts it is often useful to access the standard streams available to the operating system such as standard input/output and error. How does one access these streams in PHP 5/7?





Question: 71 (ID:538)

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;                    



Question: 72 (ID:286)

ID: 286


What is the work of simplexml_import_dom() in the following PHP code?


                        
 $dom = new domDocument;
 $dom->loadXML('<email><from>John</from></email>');
 $xml = simplexml_import_dom($dom);
 echo $xml->from;                    



Question: 73 (ID:153)

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?





Question: 74 (ID:802)

ID: 802


If a function signature contains three parameters, for which of them may the splat operator be used?





Question: 75 (ID:439)

ID: 439


What is PDO::query() equivalent to?