Test HTTP Requests Tools Blog PHP Quiz API Log In With Github
Test HTTP Requests Tools Blog PHP Quiz API Log In With Github
You are seeing the archive version of the website.
Click here to go to the live website

We have updated the website and our policies to make sure your privacy rights and security are respected.
Click here to learn more about the way our website handles your data.

Remove this message.

Advanced PHP Quiz

Topic: PHP/MySQL Last updated on: 01-22-2018

This is an advanced PHP Quiz. It contains questions for seasoned developers about namespaces, traits, handlers and settings, command line execution, exception handling, OOP and other modern PHP features and functions.

1.Considering the code below, which of these statements are true?


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


2.What is the output of the following script ?


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

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

4.Which of the statements about traits below are true ?

5.When running PHP's built in FastCGI Process Manager (FPM) which of the following statements are true ?

6.Considering the following code which of the statements below is true ?


    class entity {
        public $name;
    }
    $human = new entity();
    $dog = new entity();
    $human->name = 0;
    $dog->name = "";

7.Which of th following statements about object serialization are true ?

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

9.Which from the following list is not an appropriate use of an array?

10.What is the output of this code snippet? $a = array(0.001 => 'b', .1 => 'c'); var_dump($a);

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

12.What is the output of the following code block? $array = array(1 => 0, 2, 3, 4); array_splice($array, 3, count($array), array_merge(array('x'), array_slice($array, 3))); var_dump($array);

13.Which key will not be displayed from the following code block? $array = array('a' => 'John', 'b' => 'Coggeshall', 'c' => array('d' => 'John', 'e' => 'Smith')); function display($item, $key) { print "$key => $item\n"; } array_walk_recursive($array, "display");

14.The ____ construct is particularly useful to assign your own variable names to values within an array.

15.What is the best way to iterate and modify every element of an array using PHP 5?

16.What is the output of the following PHP code? define("FOO", 10); $array = [10 => FOO,"FOO" => 20]; print $array[$array[FOO]] * $array["FOO"];

17.What is the output of the following PHP script? $a = 1; $b = 2.5; $c = 0xFF; $d = $b + $c; $e = $d * $b; $f = ($d + $e) % $a; print ($f + $e);

18.What SimpleXML function is used to parse a file?

19.How does one access standard input/output and error streams in PHP 5?

20.When checking to see if two variables contain the same instance of an object, which of the following comparisons should be used?

21.The _______ method will be called automatically when an object is represented as a string.

22.Which php.ini directive should be disabled to prevent the execution of a remote PHP script via an include or require construct?

23.Which of the following are not valid ways to embed a variable into a string?

24.What variable reference would go in the spots indicated 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;

25.Identify the best approach to compare two variables in a binary-safe fashion

26.Which PCRE regular expression will match the string PhP5-rocks

27.If you would like to store your session in the database, you would do which of the following?

28.When uploading a file using HTTP, which variable can be used to locate the file on PHP's local filesystem?

29.How does one create a cookie which will exist only until the browser session is terminated?

30.Which of the following is not a valid fopen() access mode:

Finish Quiz