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 is the output of the code below ?


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

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.Which of the statements about traits below are true ?

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

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

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

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

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

9.The following code snippet displays what for the resultant array? $a = array(1 => 0, 3 => 2, 4 => 6); $b = array(3 => 1, 4 => 3, 6 => 4); print_r(array_intersect($a, $b));

10.Which of the following tags are an acceptable way to begin a PHP Code block?

11.What is the output of the following? $a = 010; $b = 0xA; $c = 2; print $a + $b + $c;

12.What is the best way to ensure that a user-defined function is always passed an object as its single parameter?

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

14.How does one access standard input/output and error streams in PHP 5?

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

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

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

18.What is the output of the following script? class ClassOne { protected $a = 10; public function changeValue($b) { $this->a = $b; } } class ClassTwo extends ClassOne { protected $b = 10; public function changeValue($b) { $this->b = 10; parent::changeValue($this->a + $this->b); } public function displayValues() { print "a: {$this->a}, b: {$this->b}\n"; } } $obj = new ClassTwo(); $obj->changeValue(20); $obj->changeValue(10); $obj->displayValues();

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

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

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

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

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

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

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

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

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

28.Consider the following HTML fragment: <select name="???????" multiple> <option value="1">Item #1</option> <!-- ... more options ... --> </select> Which of the following name attributes should be used to capture all of the data from the user in PHP?

29.How does one create a cookie which will exist only until the browser session is terminated?

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

Finish Quiz