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

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

3.What happens when the code below is executed ?


  <?php
    class foo
    {
      private $variable;

      function __construct()
      {
        $this->variable = 1;
      }

      function __get($name)
      {
        return $this->$name;
      }
    }
    $a = new foo;
    echo $a->variable;
  ?>

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

5.When dealing with cloned objects in PHP, which of the following statements are true ?

6.What happens if you execute the code below ?


<?php
    class someclass
    {
        public $someprop;
        
        function __construct()
        {
            $this->someprop = 1;
        }
    }

    function somefunc(&$instance) {
        unset($instance);
    }

    $instance = new someclass;
    somefunc($instance);
    var_dump($instance);


7.What is the output of the following PHP script?

                    <?php 
                        $a = 1;
                        $b = 2.5;
                        $c = 0xFF;
                        $d = $b + $c;
                        $e = $d * $b;
                        $f = ($d + $e) % $a;
                        print ($f + $e);
                  

8.How do you access standard I/O and error streams ?

9.Which of the following functions will sort an array in ascending order by value, while preserving key associations?

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

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

14.Consider the following table data and PHP code. What is the outcome? Table data (table name "users" with primary key "id"): id name email ------- ----------- ------------------- 1 anna [email protected] 2 betty [email protected] 3 clara [email protected] 5 sue [email protected] PHP code (assume the PDO connection is correctly established): $dsn = 'mysql:host=localhost;dbname=exam'; $user = 'username'; $pass = '********'; $pdo = new PDO($dsn, $user, $pass); $cmd = "SELECT * FROM users WHERE id = :id"; $stmt = $pdo->prepare($cmd); $id = 3; $stmt->bindParam('id', $id); $stmt->execute(); $stmt->bindColumn(3, $result); $row = $stmt->fetch(PDO::FETCH_BOUND);

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

16.What is the difference between the ``include`` and ``require`` language constructs?

17.What is the output of the following? $a = 20; function myfunction($b) { $a = 30; global $a, $c; return $c = ($b + $a); } print myfunction(40) + $c;

18.The ______ keyword is used to indicate an incomplete class or method, which must be further extended and/or implemented in order to be used.

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

20. Which of the following list of potential data sources should be considered trusted?

21.Consider the following code: header("Location: {$_GET['url']}\"); Which of the following values of $_GET['url'] would cause session fixation?

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

23.Which of the following is the best way to split a string on the "-=-" pattern?

24.What is the output of the following code? $string = "14302"; $string[$string[2]] = "4"; print $string;

25.Which string does the following PCRE regular expression match? $regex = "/^([a-z]{5})[1-5]+([a-z]+)/";

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.If you would like to change the session ID generation function, which of the following is the best approach for PHP 5?

29.During an HTTP authentication, how does one determine the username and password provided by the browser?

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

Finish Quiz