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

2.What is the output of the code below ?

  
    <?php
    $a = array('one'=>'php', 'two'=>'javascript', 'three'=>'python');
    $b = array('python', 'javascript', 'php');

    if(array_values(array_reverse($a)) === $b)
      echo 'true';
    else
      echo 'false';
  

3.What is the best way to store and verify passwords in PHP ?

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


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

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

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

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

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

10.If you wanted a variable containing the letters A through Z, that allowed you to access each letter independently, which of the following approaches could you use?

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

12.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?

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

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

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

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.How does one access standard input/output and error streams in PHP 5?

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

20.What is the primary difference between a method declared as static and a normal method?

21.To ensure that a given object has a particular set of methods, you must provide a method list in the form of an ________ and then attach it as part of your class using the ________ keyword.

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

23.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?

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

25.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?

26.For an arbitrary string $mystring, which of the following checks will correctly determine if the string PHP exists within it?

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

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

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

30.Setting a cookie on the client in PHP 5 can be best accomplished by:

Finish Quiz