Full-Course Mock Papers

5 mock papers of 41 questions each – one question from every chapter and the project. They are the same papers as Part VII of the e-book. Answer all questions and press Submit Test to see your score; each answer has an explanation and a link to the chapter it comes from.

41 questions · 1 mark each Time taken: 00:00 Answered: 0 / 41 Printable papers (PDF)
Mock Paper 5

Q1. To receive several checked checkboxes as an array, the field name should be:

Show Answer

Correct Answer : C. hobby[]
The [] suffix makes PHP collect the values into an array. (From Chapter 11 : PHP Form Handling)

Q2. Which replaces the removed __autoload() function?

Show Answer

Correct Answer : B. spl_autoload_register()
Register autoloaders with spl_autoload_register(). (From Chapter 17 : Object-Oriented PHP – Classes and Objects)

Q3. Which parameter of mail() is optional?

Show Answer

Correct Answer : D. headers
headers (and parameters) are optional. (From Chapter 15 : PHP and E-Mail)

Q4. A constant created with define() is used:

Show Answer

Correct Answer : D. Without a $ prefix
Constants are referenced by name only, e.g. SUBJECT. (From Chapter 4 : Constants, Variables and Data Types)

Q5. Since PHP 8.1, a failed MySQLi query by default:

Show Answer

Correct Answer : A. Throws mysqli_sql_exception
The default report mode is ERROR | STRICT. (From Chapter 34 : PHP and MySQLi – Procedural Style)

Q6. The third argument of xhr.open("GET", url, true) makes the request:

Show Answer

Correct Answer : A. Asynchronous
true = asynchronous. (From Chapter 39 : PHP and AJAX)

Q7. How many times does for ($i = 0; $i < 5; $i++) execute its body?

Show Answer

Correct Answer : C. 5
i takes the values 0, 1, 2, 3 and 4. (From Chapter 7 : Looping Statements)

Q8. Which database server does current XAMPP actually ship under the "MySQL" label?

Show Answer

Correct Answer : A. MariaDB
Since 2015 XAMPP has shipped MariaDB, a drop-in replacement for MySQL. (From Chapter 1 : AMP Basics – Apache, MySQL and PHP)

Q9. Which function was removed in PHP 5.4?

Show Answer

Correct Answer : B. session_register()
Use $_SESSION instead. (From Chapter 31 : State Management – Sessions)

Q10. Which function reads a single line from a file?

Show Answer

Correct Answer : D. fgets()
fgets() reads one line. (From Chapter 14 : PHP and the File System)

Q11. A nowdoc identifier is written as:

Show Answer

Correct Answer : C. <<<'EOT'
The identifier in single quotes marks a nowdoc. (From Chapter 8 : PHP and Strings)

Q12. Which statement about print is TRUE?

Show Answer

Correct Answer : D. It always returns 1
print outputs one string and returns 1. (From Chapter 3 : PHP – Hypertext Preprocessor: Introduction and Syntax)

Q13. Which magic method runs when a value is written to an inaccessible property?

Show Answer

Correct Answer : B. __set()
__set() handles writes. (From Chapter 18 : Object-Oriented PHP – Abstraction, Overloading, Iteration and Patterns)

Q14. Which function should replace the removed /e modifier?

Show Answer

Correct Answer : C. preg_replace_callback()
It calls a function for each match safely. (From Chapter 12 : Form Validation and Regular Expressions)

Q15. What is __NAMESPACE__ in the global space?

Show Answer

Correct Answer : D. An empty string
It contains the current namespace name, empty in the global space. (From Chapter 16 : PHP Namespaces)

Q16. Which function installs a user-defined error handler?

Show Answer

Correct Answer : A. set_error_handler()
set_error_handler() registers the function. (From Chapter 20 : Error and Exception Handling)

Q17. strcmp("apple", "apple") returns:

Show Answer

Correct Answer : B. 0
Equal strings give 0. (From Chapter 29 : String, Variable and Miscellaneous Functions)

Q18. Which closes an if block written in alternative syntax?

Show Answer

Correct Answer : D. endif;
Alternative syntax uses endif;. (From Chapter 6 : Conditional Statements)

Q19. WHERE name LIKE 'A%' finds names that:

Show Answer

Correct Answer : B. Start with A
% matches any characters after A. (From Chapter 32 : Database Support and MySQL Fundamentals)

Q20. Which statement publishes an article?

Show Answer

Correct Answer : B. UPDATE cms_articles SET is_published = 1, publish_date = NOW() WHERE article_id = ?
Publishing updates the status and publish date. (From Project 1 : Project – A Mini Content Management System with PHP and MySQLi)

Q21. Which function keeps key/value pairs while sorting by value in descending order?

Show Answer

Correct Answer : C. arsort()
arsort() sorts by value descending and preserves keys. (From Chapter 23 : Apache and Array Functions)

Q22. Which function returns the name of an object's class?

Show Answer

Correct Answer : A. get_class()
get_class($obj) returns the class name. (From Chapter 25 : Class/Object, Function Handling, Directory and File Functions)

Q23. Which file must be edited to change the PHP upload limit?

Show Answer

Correct Answer : A. php.ini
upload_max_filesize and post_max_size are PHP settings in php.ini. (From Chapter 2 : XAMPP – Installation, Configuration and Use)

Q24. Which component renders output for the user?

Show Answer

Correct Answer : C. View
The view presents data. (From Chapter 19 : PHP and MVC (Model–View–Controller))

Q25. Options -Indexes prevents:

Show Answer

Correct Answer : A. Directory listings
Folders without an index file are no longer listed. (From Chapter 22 : .htaccess Security)

Q26. Which function changes a php.ini setting for the current script only?

Show Answer

Correct Answer : D. ini_set()
ini_set() changes the option at run time. (From Chapter 28 : Network, Output Buffer, Configuration and Session Functions)

Q27. Which feature of MySQLi prevents SQL injection?

Show Answer

Correct Answer : C. Prepared statements
Parameters are sent separately from the SQL text. (From Chapter 27 : MySQL Functions and their MySQLi Equivalents)

Q28. odbc_result($rs, "CompanyName") returns:

Show Answer

Correct Answer : B. The value of the CompanyName field of the current row
Fields can be read by name or number. (From Chapter 37 : Database Support using ODBC)

Q29. HTTP is a ______ protocol.

Show Answer

Correct Answer : A. stateless
Each request is independent. (From Chapter 30 : State Management – Cookies and Query Strings)

Q30. What is the value of 2 + 3 * 3?

Show Answer

Correct Answer : C. 11
* has higher precedence than +, so 3 * 3 = 9 is computed first. (From Chapter 5 : Operators and Expressions)

Q31. Which PHP function loads an XML file into a SimpleXMLElement?

Show Answer

Correct Answer : C. simplexml_load_file()
simplexml_load_file() returns the object. (From Chapter 38 : XML with PHP)

Q32. mysql_fetch_array() returns a row as:

Show Answer

Correct Answer : B. An associative and numeric array
Both $row['name'] and $row[1] work. (From Chapter 33 : PHP and MySQL – The Classic mysql API)

Q33. Which keyword defines a function?

Show Answer

Correct Answer : C. function
PHP functions are declared with the function keyword. (From Chapter 10 : User-Defined Functions)

Q34. require_once prevents:

Show Answer

Correct Answer : D. Loading a file more than once
It skips files that have already been loaded. (From Chapter 13 : Server Side Includes – include and require)

Q35. The main reason users return to a web site is:

Show Answer

Correct Answer : A. Regularly updated content
New information brings visitors back. (From Chapter 40 : Content Management System (CMS) – Concepts)

Q36. Which statement creates a MySQLi connection object?

Show Answer

Correct Answer : D. new mysqli(...)
The mysqli constructor opens the connection. (From Chapter 35 : PHP and MySQLi – Object-Oriented Style)

Q37. For a secure OTP you should use:

Show Answer

Correct Answer : A. random_int()
random_int() is cryptographically secure. (From Chapter 26 : Error, HTTP, Mail and Mathematical Functions)

Q38. date("H") returns the hour in:

Show Answer

Correct Answer : B. 24-hour format with leading zero
H is 00–23. (From Chapter 24 : Date, Time and Calendar Functions)

Q39. Which filter is deprecated in PHP 8.1?

Show Answer

Correct Answer : B. FILTER_SANITIZE_STRING
Use htmlspecialchars() or FILTER_SANITIZE_FULL_SPECIAL_CHARS instead. (From Chapter 21 : PHP Filters)

Q40. Which function checks a password against a stored hash?

Show Answer

Correct Answer : C. password_verify()
password_verify() compares a password with a hash. (From Chapter 36 : MySQLi Prepared Statements, Transactions and Security)

Q41. $ages = ["Peter" => 32]; creates a(n):

Show Answer

Correct Answer : D. Associative array
The string key "Peter" makes it associative. (From Chapter 9 : PHP and Arrays)