PHP Mastery Quiz: Test Your Practical PHP Knowledge! Quiz

  1. Working with Sessions

    What must you do before accessing the $_SESSION superglobal in PHP?

    1. Call session_start()
    2. Include 'session.php'
    3. Call session_init()
    4. Use session_get()
    5. Set session_enable = true
  2. JSON Handling

    Which function should you use to convert a PHP array into a JSON string?

    1. json_encode()
    2. json_decode()
    3. encode_json()
    4. array_to_json()
    5. toJSON()
  3. Handling File Uploads

    What is one important security step when accepting uploaded files in PHP?

    1. Validate the file type
    2. Check $_POST for file data
    3. Use save_file() function
    4. Set file_permissions = 777
    5. Echo the file contents before saving
  4. Recursive Functions

    Which of the following best describes a recursive function?

    1. A function that calls itself
    2. A function that runs forever
    3. A function that only uses loops
    4. A function with no return keyword
    5. A static function
  5. PDO vs MySQLi

    Why might you choose PDO over MySQLi for database access in PHP?

    1. PDO supports multiple database types
    2. PDO is only for procedural code
    3. PDO requires XML configuration
    4. PDO is deprecated
    5. PDO does not need prepared statements
  6. Preventing Double Form Submissions

    What is a common technique to prevent a form from being submitted twice in PHP?

    1. Use a session variable
    2. Disable the submit button with CSS
    3. Double the action URL
    4. Increase max_input_vars
    5. Add a second submit button
  7. Magic Methods

    What is true about magic methods in PHP?

    1. They start with double underscores, like __get
    2. They are only for arrays
    3. They must be private functions
    4. They are declared with 'magic' keyword
    5. They are deprecated features
  8. Generators

    How do generators help when working with large data sets in PHP?

    1. They yield one value at a time without storing all values in memory
    2. They sort arrays automatically
    3. They compress the data automatically
    4. They convert arrays to JSON
    5. They duplicate the dataset
  9. Error Handling

    How do you catch exceptions in PHP?

    1. Using try-catch blocks
    2. With on_error() handler
    3. By checking $_ERRORS
    4. Using the catch_error() function
    5. Placing code in a safe block
  10. Anonymous Functions and Closures

    What distinguishes a closure from a regular anonymous function in PHP?

    1. A closure can access variables outside its scope using the use keyword
    2. Closures must have return types
    3. Closure functions only work with integers
    4. Closures cannot be assigned to variables
    5. Closures must be named