Test HTTP Requests Tools Blog PHP Quiz API Log In With Github
Test HTTP Requests Tools Blog PHP Quiz API Log In With Github
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?

    ini_set("allow_url_fopen", "1");
    $page = file_get_contents("http://www.codepunker.com");
    echo "Successfully fetched website contents";
    echo "An error has occurred";

2.What happens when you run the following MySQL Query ?


3.What is the output of the following script ?

  function generate() {
      for ($i = 1; $i <= 3; $i++) 
          yield $i;
  $generator = generate();
    echo "Is Array";
    echo "Is Object";
    echo "Is none of the above";

4.What is the output of the code below ?

    $now  = new DateTime();
    $now2 = new DateTime();

    $ago  = new DateInterval('P4Y10M3W');
    $ago2 = new DateInterval('P4Y10M2W7D');

    $then  = $now->sub($ago);
    $date1 = $then->format('Y-m-d');

    $then2 = $now2->sub($ago2);
    $date2 = $then2->format('Y-m-d');

    var_dump ($date1 === $date2);

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

6.What happens if you execute the code below ?

    class someclass
        public $someprop;
        function __construct()
            $this->someprop = 1;

    function somefunc(&$instance) {

    $instance = new someclass;

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

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

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

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

11.Which technique should be used to speed up joins without changing their results?

12.What is the best way to ensure that a user-defined function is always passed an object as its single parameter?

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

14.What would go in place of ?????? below to make this script execute without a fatal error? $a = 1; $b = 0; /* ?????? */ $c = $a / $b;

15.What is the output of the following function? function &find_variable(&$one, &$two, &$three) { if($one > 10 && $one < 20) return $one; if($two > 10 && $two < 20) return $two; if($three > 10 && $three < 20) return $three; } $one = 2; $two = 20; $three = 15; $var = &find_variable($one, $two, $three); $var++; print "1: $one, 2: $two, 3: $three";

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

17.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.

18.How can you modify the copy of an object during a clone operation?

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

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

21.Consider the following code: session_start(); if(!empty($_REQUEST['id']) && !empty($_REQUEST['quantity'])) { $id = scrub_id($_REQUEST['id']); $quantity = scrub_quantity($_REQUEST['quantity']) $_SESSION['cart'][] = array('id' => $id, 'quantity' => $quantity) } /* .... */ What potential security hole would this code snippet produce?

22.What is the best measure one can take to prevent a cross-site request forgery?

23.When comparing two strings, which of the following is acceptable?

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

25.To destroy one variable within a PHP session you should use which method in PHP 5?

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

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

28.Consider the following HTML fragment: <select name="???????" multiple> <option value="1">Item #1</option> <!-- ... more options ... --> </select> Which of the following name attributes should be used to capture all of the data from the user in PHP?

29.To force a user to redirect to a new URL from within a PHP 5 script, which of the following should be used?

30.Setting a HTTP cookie on the client which is not URL-encoded is done how in PHP 5?

Finish Quiz