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

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

5.What is the output of the code below ?

  
    <?php
    namespace animals;

    ini_set('error_reporting', E_ALL);
    ini_set('display_errors', 'on');

    class Cat
    {
      static function Definition()
      {
        return 'Cats are ' . __NAMESPACE__;
      }
    }

    namespace animals\pets;

    class Cat
    {
      static function Definition()
      {
        return 'Cats are ' . __NAMESPACE__;
      }
    }

    echo Cat::Definition();    
  

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

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

8.Which of the following is not valid syntax for creating a new array key?

9.What is the output of this code snippet? $a = array(0.001 => 'b', .1 => 'c'); var_dump($a);

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

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

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.Which of the following tags are an acceptable way to begin a PHP Code block?

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.Transactions are used to...

17.What is the difference between the ``include`` and ``require`` language constructs?

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

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

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

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

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

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

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

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

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

27.Consider the following script: $oranges = 10; $apples = 5; $string = "I have %d apples and %d oranges"; ??????? What could be placed in place of ?????? to output the string: "I have 5 apples and 10 oranges"

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