Test HTTP Requests Tools Blog Learn Quizzes Smile API Log In / Sign Up
Test HTTP Requests Tools Blog Learn Quizzes Smile API Log In / Sign Up
« Return to the quizzes list
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 ...

  
    <?php 
        
    class AppException extends Exception
    {
      function __toString()
      {
        return "Your code has just thrown an exception: {$this->message}\n";
      }
    }

    class Students
    {
      public $first_name;
      public $last_name;

      public function __construct($first_name, $last_name)
      {
        if(empty($first_name))
        {
          throw new AppException('First Name is required', 1);
        }

        if(empty($last_name))
        {
          throw new AppException('Last Name is required', 2);
        }
      }
    }

    try {
     new Students('', ''); 
    } catch (Exception $e) {
      echo $e;
    }
  

... which of these statements are correct ?

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

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

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

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

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

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

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

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

10.Which of the following are valid PHP variables?

11.Given a PHP value, which sample shows how to convert the value to JSON?

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

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

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

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

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

17.What three special methods can be used to perform special logic in the event a particular accessed method or member variable is not found?

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

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

20.When implementing a permissions system for your Web site, what should always be done with regards to the session?

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

22.Which function is best suited for removing markup tags from a string?

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

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

25.If regular expressions must be used, in general which type of regular expression functions available to PHP is preferred for performance reasons?

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.Setting a cookie on the client in PHP 5 can be best accomplished by:

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

30.Which functions would be needed to translate the following string: I love PHP 5 to the following? 5 PHP EVOL I

Finish Quiz