Main Snake Zend Zend Questions Exam Quicktest MZend

1h 30m 00s


Question: 1 (ID:520)

ID: 520


Which of the following are examples of the new engine executor models available in PHP 5?





Question: 2 (ID:789)

ID: 789


Give the following expression: "$$foo['bar']". Which of the statements below are true?





Question: 3 (ID:63)

ID: 63


You run the following PHP script:


                        
$a = "b";
$b = 20;
echo $$a;                    

What will be the output?



Question: 4 (ID:696)

ID: 696


When working with unfamiliar code, what is the best way to find out in which file a class is defined ?





Question: 5 (ID:563)

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



Question: 6 (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: 7 (ID:61)

ID: 61


Which of the following functions allows you to stack several error handlers on top of each other?





Question: 8 (ID:350)

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



Question: 9 (ID:450)

ID: 450


What is the output of:


                        
$a = "0";
echo strlen($a);
echo empty($a) ? $a : 5;
echo $a ?: 5;                    



Question: 10 (ID:232)

ID: 232


Consider the following code snippet:


                        
$hello = 'world';
$world = 'hello';
echo $$$hello;                    

What will be the output?



Question: 11 (ID:74)

ID: 74


Consider the following code:


                        
$array = array("a1"=>'x', "a2"=>'e', "a3"=>'z');
asort($array);
foreach ($array as $keys => $values) {
    print "$keys = $values";
}                    

What will be the output?



Question: 12 (ID:163)

ID: 163


Consider a scenario in which a website allows users to upload pictures. What kind of security should be set to prevent attacks?





Question: 13 (ID:56)

ID: 56


You run the following PHP script:


                        
$a = 20 % -8;
echo $a;                    



Question: 14 (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: 15 (ID:367)

ID: 367


What is the output of the following PHP script?


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



Question: 16 (ID:589)

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



Question: 17 (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: 18 (ID:515)

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!");                    



Question: 19 (ID:783)

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



Question: 20 (ID:106)

ID: 106


Which of the following operators will you use to check whether two variables contain the same instance of an object or not?





Question: 21 (ID:11)

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



Question: 22 (ID:265)

ID: 265


Which of the following HTML code snippets can be used for the file uploading?





Question: 23 (ID:243)

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?



Question: 24 (ID:33)

ID: 33


You run the following PHP script:


                        
<?php echo 0x33, ' birds sit on ', 022, ' trees.';                    

What will be the output?



Question: 25 (ID:374)

ID: 374


What is the output of the following PHP code?


                        
$myArray = [0, NULL, '', '0', -1];
echo count(array_filter($myArray));                    



Question: 26 (ID:491)

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



Question: 27 (ID:148)

ID: 148


Which of the following PHP functions will you use as a countermeasure against a cross-site scripting (XSS) attack?





Question: 28 (ID:385)

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?



Question: 29 (ID:545)

ID: 545


How do you declare a function to accept a variable (unknown) number of arguments in PHP 7?





Question: 30 (ID:765)

ID: 765


Of the following statements about typehints, which is NOT true?





Question: 31 (ID:175)

ID: 175


What is the default timeout of a session cookie?





Question: 32 (ID:689)

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



Question: 33 (ID:653)

ID: 653


What is the output of the following code?


                        
function byReference(&$variable = 0){
    echo ++$variable;
}    
byReference();
byReference();                    



Question: 34 (ID:701)

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



Question: 35 (ID:288)

ID: 288


Which of the following is an associative array of items uploaded by the current PHP script via the HTTP POST method?





Question: 36 (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: 37 (ID:806)

ID: 806


Which of the following types can be used as an array key? (Select three.)





Question: 38 (ID:305)

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)





Question: 39 (ID:553)

ID: 553


Which functions would be needed to translate the following string:


                        
I love PHP 5
                    

to the following?



Question: 40 (ID:329)

ID: 329


What is the output of the following PHP script?


                        
$name = 'Joe';
$$name = 'Bloggs';
echo ${$name};                    

Enter the exact script output



Question: 41 (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: 42 (ID:619)

ID: 619


The MVC pattern in Web development involves which of the following components?





Question: 43 (ID:246)

ID: 246


Which of the following statements describes the use of a GROUP BY clause?





Question: 44 (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: 45 (ID:194)

ID: 194


Which function is used to set up start and end element handlers?





Question: 46 (ID:623)

ID: 623


What is the output of the following code?


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



Question: 47 (ID:773)

ID: 773


What is the result of the following code?


                        
<?= (function(){ return [$x, $x + 1, $x + 2];})(4)[2];                    



Question: 48 (ID:356)

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" ?>                    



Question: 49 (ID:486)

ID: 486


What does the following code output?


                        
$i = function($j) {
   $i = $j + 4;
   return $i++;
};
$j = 6;
echo $i($j);                    



Question: 50 (ID:565)

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



Question: 51 (ID:108)

ID: 108


You passed an associative array to the sort() function. What will happen?





Question: 52 (ID:170)

ID: 170


Which function is used to get a specific external variable by name and optionally filter it?





Question: 53 (ID:464)

ID: 464


Which of the following is a valid namespace operator in PHP?





Question: 54 (ID:709)

ID: 709


How does Opcode Cache improve performance in PHP 5.5+ ?





Question: 55 (ID:532)

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?





Question: 56 (ID:720)

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



Question: 57 (ID:606)

ID: 606


How do you define an array in PHP7?





Question: 58 (ID:533)

ID: 533


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?



Question: 59 (ID:426)

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



Question: 60 (ID:713)

ID: 713


What is the result of the code below?


                        
echo ("0.00") ? "mary" : "angie";                    



Question: 61 (ID:131)

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?





Question: 62 (ID:693)

ID: 693


What is the default value for the "max_execution_time" setting when running PHP as a CLI SAPI ?





Question: 63 (ID:162)

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.





Question: 64 (ID:50)

ID: 50


Which of the following is a magic constant?





Question: 65 (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: 66 (ID:519)

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?





Question: 67 (ID:116)

ID: 116


Which of the following variables are NOT supported by type hinting (PHP < 7)? Each correct answer represents a complete solution. Choose two.





Question: 68 (ID:4)

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



Question: 69 (ID:171)

ID: 171


Which of the following functions wraps a string to a given number of characters?





Question: 70 (ID:196)

ID: 196


All of the following are the pre-defined entities except for which one?





Question: 71 (ID:37)

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;                    



Question: 72 (ID:368)

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.





Question: 73 (ID:211)

ID: 211


Which of the following function is used to parse XML data into an array structure?





Question: 74 (ID:372)

ID: 372


What is the primary difference between array_key_exists() and isset() when checking to see if a given array element exists?





Question: 75 (ID:358)

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)?