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 1

Q1. Which function rounds 4.1 up to 5?

Show Answer

Correct Answer : D. ceil()
ceil() always rounds up. (From Chapter 26 : Error, HTTP, Mail and Mathematical Functions)

Q2. Which function validates a date?

Show Answer

Correct Answer : C. checkdate()
checkdate(month, day, year) returns true or false. (From Chapter 24 : Date, Time and Calendar Functions)

Q3. In the project, an access_level of 2 means:

Show Answer

Correct Answer : B. Moderator
1 = user, 2 = moderator, 3 = administrator. (From Project 1 : Project – A Mini Content Management System with PHP and MySQLi)

Q4. Which function was removed in PHP 8.0?

Show Answer

Correct Answer : C. create_function()
create_function() was removed; use closures. (From Chapter 25 : Class/Object, Function Handling, Directory and File Functions)

Q5. In SimpleXML, the attribute id of $book is read as:

Show Answer

Correct Answer : B. $book['id']
Attributes are accessed like array elements. (From Chapter 38 : XML with PHP)

Q6. Which enctype is required for file uploads?

Show Answer

Correct Answer : C. multipart/form-data
Binary file data needs multipart/form-data. (From Chapter 14 : PHP and the File System)

Q7. 5 === "5" evaluates to:

Show Answer

Correct Answer : A. false
=== also compares types; int and string differ. (From Chapter 5 : Operators and Expressions)

Q8. In OOP style, the number of rows in a SELECT result is:

Show Answer

Correct Answer : D. $result->num_rows
num_rows is a property of mysqli_result. (From Chapter 35 : PHP and MySQLi – Object-Oriented Style)

Q9. Which statement selects one of many blocks by comparing one value with several labels?

Show Answer

Correct Answer : C. switch
switch compares one expression with many case labels. (From Chapter 6 : Conditional Statements)

Q10. Which Control Panel button shows which program is using a port?

Show Answer

Correct Answer : C. Netstat
Netstat lists all ports in use and the programs using them. (From Chapter 2 : XAMPP – Installation, Configuration and Use)

Q11. In a CMS, content should be:

Show Answer

Correct Answer : B. Separate from the design
Content and design are maintained independently. (From Chapter 40 : Content Management System (CMS) – Concepts)

Q12. Which interface needs only the getIterator() method?

Show Answer

Correct Answer : D. IteratorAggregate
IteratorAggregate returns an iterator from getIterator(). (From Chapter 18 : Object-Oriented PHP – Abstraction, Overloading, Iteration and Patterns)

Q13. Which function returns one column of a two-dimensional array?

Show Answer

Correct Answer : A. array_column()
array_column($rows, "name") extracts that column. (From Chapter 23 : Apache and Array Functions)

Q14. Which of these is a server-side state management option?

Show Answer

Correct Answer : A. Session
Session data is stored on the server. (From Chapter 30 : State Management – Cookies and Query Strings)

Q15. In the convention described, which file type should contain no SQL?

Show Answer

Correct Answer : B. .phtml
Templates (.phtml) never contain SQL queries. (From Chapter 19 : PHP and MVC (Model–View–Controller))

Q16. Inside a static method you cannot use:

Show Answer

Correct Answer : A. $this
There is no object in a static context. (From Chapter 17 : Object-Oriented PHP – Classes and Objects)

Q17. [^0-9] matches:

Show Answer

Correct Answer : C. Any non-digit character
^ at the start of a class negates it. (From Chapter 12 : Form Validation and Regular Expressions)

Q18. Which function converts array keys into variables?

Show Answer

Correct Answer : D. extract()
extract() creates variables from array keys. (From Chapter 9 : PHP and Arrays)

Q19. Which is the best choice for a database connection file?

Show Answer

Correct Answer : B. require_once
The page cannot work without it and it should load only once. (From Chapter 13 : Server Side Includes – include and require)

Q20. Which php.ini line enables ODBC?

Show Answer

Correct Answer : B. extension=odbc
Remove the semicolon before extension=odbc. (From Chapter 37 : Database Support using ODBC)

Q21. Which array holds values sent by a form with method="post"?

Show Answer

Correct Answer : C. $_POST
POST data is available in $_POST. (From Chapter 11 : PHP Form Handling)

Q22. Which function returns all rows of a result at once?

Show Answer

Correct Answer : C. mysqli_fetch_all()
It returns an array of all rows. (From Chapter 34 : PHP and MySQLi – Procedural Style)

Q23. Which module provides RewriteRule?

Show Answer

Correct Answer : A. mod_rewrite
mod_rewrite implements URL rewriting. (From Chapter 22 : .htaccess Security)

Q24. Where is session data stored?

Show Answer

Correct Answer : B. On the server
Only the session id is sent to the browser. (From Chapter 31 : State Management – Sessions)

Q25. Prepared statements protect against:

Show Answer

Correct Answer : C. SQL injection
Data is sent separately from the SQL code. (From Chapter 36 : MySQLi Prepared Statements, Transactions and Security)

Q26. What does php_sapi_name() return under XAMPP's Apache?

Show Answer

Correct Answer : D. apache2handler
PHP runs as an Apache module. (From Chapter 28 : Network, Output Buffer, Configuration and Session Functions)

Q27. How do you pass a parameter by reference?

Show Answer

Correct Answer : D. &$n
The ampersand before the parameter passes the variable by reference. (From Chapter 10 : User-Defined Functions)

Q28. What does "10" + 5 evaluate to?

Show Answer

Correct Answer : B. 15
The + operator converts the numeric string to a number (type juggling). (From Chapter 4 : Constants, Variables and Data Types)

Q29. Which of these is case-sensitive in PHP?

Show Answer

Correct Answer : C. Variable names
$color and $COLOR are different variables; keywords and function names are not case-sensitive. (From Chapter 3 : PHP – Hypertext Preprocessor: Introduction and Syntax)

Q30. The default level of trigger_error() is:

Show Answer

Correct Answer : B. E_USER_NOTICE
Without a second argument it raises E_USER_NOTICE. (From Chapter 20 : Error and Exception Handling)

Q31. The term "open source" was coined in:

Show Answer

Correct Answer : D. 1998
The term was coined in 1998, after Netscape released the Navigator source code. (From Chapter 1 : AMP Basics – Apache, MySQL and PHP)

Q32. Which keyword declares a namespace?

Show Answer

Correct Answer : D. namespace
namespace Name; declares it. (From Chapter 16 : PHP Namespaces)

Q33. Which function should be used to store a password?

Show Answer

Correct Answer : C. password_hash()
password_hash() creates a salted, slow hash. (From Chapter 29 : String, Variable and Miscellaneous Functions)

Q34. Which statement removes a whole table?

Show Answer

Correct Answer : D. DROP TABLE table
DROP TABLE deletes the table and its data. (From Chapter 32 : Database Support and MySQL Fundamentals)

Q35. Running mysql_connect() on PHP 8 gives:

Show Answer

Correct Answer : B. Fatal error: Call to undefined function
The function no longer exists. (From Chapter 27 : MySQL Functions and their MySQLi Equivalents)

Q36. Mail headers in a string are separated by:

Show Answer

Correct Answer : D. \r\n
Headers are separated by CRLF. (From Chapter 15 : PHP and E-Mail)

Q37. In for (init; condition; increment), the init part runs:

Show Answer

Correct Answer : A. Only once, before the loop starts
Initialisation runs once at the beginning. (From Chapter 7 : Looping Statements)

Q38. Which property returns the server response as a string?

Show Answer

Correct Answer : D. responseText
responseText is the text of the response. (From Chapter 39 : PHP and AJAX)

Q39. The default user name of MySQL/MariaDB in XAMPP is:

Show Answer

Correct Answer : A. root
root with an empty password. (From Chapter 33 : PHP and MySQL – The Classic mysql API)

Q40. A validating filter returns what when the data is invalid?

Show Answer

Correct Answer : C. false
Validation filters return false on failure. (From Chapter 21 : PHP Filters)

Q41. What is "\x41" in a double-quoted string?

Show Answer

Correct Answer : B. A
\x41 is hexadecimal 41, the character A. (From Chapter 8 : PHP and Strings)