Working with Sessions
What must you do before accessing the $_SESSION superglobal in PHP?
- Call session_start()
- Include 'session.php'
- Call session_init()
- Use session_get()
- Set session_enable = true
JSON Handling
Which function should you use to convert a PHP array into a JSON string?
- json_encode()
- json_decode()
- encode_json()
- array_to_json()
- toJSON()
Handling File Uploads
What is one important security step when accepting uploaded files in PHP?
- Validate the file type
- Check $_POST for file data
- Use save_file() function
- Set file_permissions = 777
- Echo the file contents before saving
Recursive Functions
Which of the following best describes a recursive function?
- A function that calls itself
- A function that runs forever
- A function that only uses loops
- A function with no return keyword
- A static function
PDO vs MySQLi
Why might you choose PDO over MySQLi for database access in PHP?
- PDO supports multiple database types
- PDO is only for procedural code
- PDO requires XML configuration
- PDO is deprecated
- PDO does not need prepared statements
Preventing Double Form Submissions
What is a common technique to prevent a form from being submitted twice in PHP?
- Use a session variable
- Disable the submit button with CSS
- Double the action URL
- Increase max_input_vars
- Add a second submit button
Magic Methods
What is true about magic methods in PHP?
- They start with double underscores, like __get
- They are only for arrays
- They must be private functions
- They are declared with 'magic' keyword
- They are deprecated features
Generators
How do generators help when working with large data sets in PHP?
- They yield one value at a time without storing all values in memory
- They sort arrays automatically
- They compress the data automatically
- They convert arrays to JSON
- They duplicate the dataset
Error Handling
How do you catch exceptions in PHP?
- Using try-catch blocks
- With on_error() handler
- By checking $_ERRORS
- Using the catch_error() function
- Placing code in a safe block
Anonymous Functions and Closures
What distinguishes a closure from a regular anonymous function in PHP?
- A closure can access variables outside its scope using the use keyword
- Closures must have return types
- Closure functions only work with integers
- Closures cannot be assigned to variables
- Closures must be named