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 default value for the "max_execution_time" setting when running PHP as a CLI SAPI ?

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

3.What is the output of the code below ?


<?php 
  $a = array();
  $a[0] = 1;
  unset($a[0]);
  echo ($a != null) ? 'True' : 'False';

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

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

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

7.Which of the following functions are used with the internal array pointer to accomplish an action?

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.What is the output of the following PHP code? define("FOO", 10); $array = [10 => FOO,"FOO" => 20]; print $array[$array[FOO]] * $array["FOO"];

11.Transactions are used to...

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

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.Type-hinting and the instanceof keyword can be used to check what types of things about variables?

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

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

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

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

20.Given the two values below, which of the following possibilities will print 10 foos20 bars? $var1 = "10 foos"; $var2 = "20 bars"; print ???????;

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

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

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

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

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

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

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

28.One can ensure that headers can always be sent from a PHP script by doing what?

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

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

Finish Quiz