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?


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


2.What output will this code produce ?


<?php 
    class Disney
    {
        public $cartoon;

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

    $disney = new Disney("The Beauty and The Beast");
    $waltDisney = $disney;
    $waltDisney->cartoon = "Pinocchio";
    echo $disney->cartoon;

3.What happens when the script below is executed ?


  <?php
    namespace CustomArea;
    error_reporting(E_ALL);
    ini_set("display_errors", "on");
    function var_dump($a)
    {
      return str_replace("Weird", $a, "Weird stuff can happen");
    }
    $a = "In programming";
    echo var_dump($a);
  ?>

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

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

6.How does Opcode Cache improve performance in PHP 5.5+ ?

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

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

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

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

11.Which function would you use to add an element to the beginning of an array?

12.What is the result of the following code snippet? $array = array('a' => 'John', 'b' => 'Coggeshall', 'c' => array('d' => 'John', 'e' => 'Smith')); function something($array) { extract($array); return $c['e']; } print something($array);

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.What SimpleXML function is used to parse a file?

15.Which of the following will NOT instantiate a DateTime object with the current timestamp?

16.How to access standard error stream in PHP ?

17.What are the three access modifiers that you can use in PHP objects?

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

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

20.Type-hinting and the instanceof keyword can be used to check what types of things about variables?

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

22.Which of the following php.ini directives should be disabled to improve the outward security of your application?

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

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

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

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

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

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

29.Consider the following function: function redirect($url) { // Check to make sure we haven't already sent // the header: if(/*???????*/) { header("Location: $url"); } } What conditional should replace the ????? above?

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

Finish Quiz