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 2

Q1. The quantifier + means:

Show Answer

Correct Answer : B. 1 or more
+ requires at least one occurrence. (From Chapter 12 : Form Validation and Regular Expressions)

Q2. Classic mysql_* code on XAMPP 8 results in:

Show Answer

Correct Answer : A. Fatal error: Call to undefined function
The extension no longer exists. (From Chapter 33 : PHP and MySQL – The Classic mysql API)

Q3. Which function sorts by value and keeps the key–value association?

Show Answer

Correct Answer : B. asort()
asort() keeps keys with their values. (From Chapter 9 : PHP and Arrays)

Q4. A major benefit of MVC is:

Show Answer

Correct Answer : D. Interchangeable components
Views and controllers can be swapped without touching the model. (From Chapter 19 : PHP and MVC (Model–View–Controller))

Q5. Which separator is used in namespace names?

Show Answer

Correct Answer : B. \
PHP uses the backslash. (From Chapter 16 : PHP Namespaces)

Q6. If $v = 5, what does echo $v++; print?

Show Answer

Correct Answer : B. 5
Post-increment returns the old value, then increments. (From Chapter 5 : Operators and Expressions)

Q7. Which function lists files matching *.txt?

Show Answer

Correct Answer : C. glob()
glob() works with wildcard patterns. (From Chapter 25 : Class/Object, Function Handling, Directory and File Functions)

Q8. The Unix Epoch is:

Show Answer

Correct Answer : A. 1 January 1970 GMT
Timestamps count seconds from 1 January 1970. (From Chapter 24 : Date, Time and Calendar Functions)

Q9. In the AMP restaurant analogy, PHP plays the role of the:

Show Answer

Correct Answer : D. Waiter
PHP is the waiter – it carries the visitor's request and instructions between the patron and the kitchen. (From Chapter 1 : AMP Basics – Apache, MySQL and PHP)

Q10. Which session function was removed in PHP 5.4?

Show Answer

Correct Answer : B. session_register()
Use $_SESSION instead. (From Chapter 28 : Network, Output Buffer, Configuration and Session Functions)

Q11. A variable that keeps its value between function calls is declared with:

Show Answer

Correct Answer : A. static
static variables are initialised once and retain their value. (From Chapter 4 : Constants, Variables and Data Types)

Q12. Which PHP function turns an array into JSON?

Show Answer

Correct Answer : A. json_encode()
json_encode() produces a JSON string. (From Chapter 39 : PHP and AJAX)

Q13. The DOM parser is a:

Show Answer

Correct Answer : A. Tree-based parser
It builds the whole document as a tree. (From Chapter 38 : XML with PHP)

Q14. The default name of the session cookie is:

Show Answer

Correct Answer : B. PHPSESSID
PHPSESSID, configurable with session.name. (From Chapter 31 : State Management – Sessions)

Q15. header("Location: home.php"); is used to:

Show Answer

Correct Answer : D. Redirect the browser
The Location header tells the browser to load another URL. (From Chapter 26 : Error, HTTP, Mail and Mathematical Functions)

Q16. Which keyword creates an object?

Show Answer

Correct Answer : A. new
new instantiates a class. (From Chapter 17 : Object-Oriented PHP – Classes and Objects)

Q17. In which PHP version was the mysql extension removed?

Show Answer

Correct Answer : A. 7.0
Deprecated in 5.5, removed in 7.0. (From Chapter 27 : MySQL Functions and their MySQLi Equivalents)

Q18. What happens if break is omitted at the end of a case?

Show Answer

Correct Answer : B. Execution falls through to the next case
Without break, the following case's statements also run. (From Chapter 6 : Conditional Statements)

Q19. Which loop always executes its body at least once?

Show Answer

Correct Answer : A. do…while
do…while checks the condition after the body. (From Chapter 7 : Looping Statements)

Q20. In XAMPP, the "M" now stands for:

Show Answer

Correct Answer : B. MariaDB
XAMPP has shipped MariaDB (a drop-in replacement for MySQL) since 2015. (From Chapter 2 : XAMPP – Installation, Configuration and Use)

Q21. What does $c = require "config.php"; store in $c?

Show Answer

Correct Answer : D. The value returned by config.php
An included file can return a value to the caller. (From Chapter 13 : Server Side Includes – include and require)

Q22. The Singleton pattern makes the constructor:

Show Answer

Correct Answer : D. private
A private constructor prevents creating instances with new. (From Chapter 18 : Object-Oriented PHP – Abstraction, Overloading, Iteration and Patterns)

Q23. Which symbol does NOT start a comment in PHP?

Show Answer

Correct Answer : A. <!--
<!-- is an HTML comment and would be sent to the browser. (From Chapter 3 : PHP – Hypertext Preprocessor: Introduction and Syntax)

Q24. Which array function no longer exists in PHP 8?

Show Answer

Correct Answer : C. each()
each() was removed in PHP 8.0. (From Chapter 23 : Apache and Array Functions)

Q25. Which directive in httpd.conf must allow .htaccess files to be used?

Show Answer

Correct Answer : A. AllowOverride
AllowOverride controls what .htaccess may change. (From Chapter 22 : .htaccess Security)

Q26. ODBC stands for:

Show Answer

Correct Answer : A. Open Database Connectivity
It is a standard database API. (From Chapter 37 : Database Support using ODBC)

Q27. $conn->insert_id returns:

Show Answer

Correct Answer : A. The AUTO_INCREMENT id of the last INSERT
It is the id generated by the last INSERT. (From Chapter 35 : PHP and MySQLi – Object-Oriented Style)

Q28. Which header is needed for HTML mail?

Show Answer

Correct Answer : A. Content-type: text/html
Together with MIME-Version: 1.0. (From Chapter 15 : PHP and E-Mail)

Q29. Which function gives the number of rows changed by UPDATE?

Show Answer

Correct Answer : C. mysqli_affected_rows()
It reports rows affected by the last change. (From Chapter 34 : PHP and MySQLi – Procedural Style)

Q30. A newly submitted article in the project CMS has the status:

Show Answer

Correct Answer : D. Pending
It waits for a moderator to publish it. (From Chapter 40 : Content Management System (CMS) – Concepts)

Q31. In bind_param("sid", $a, $b, $c), $b is bound as:

Show Answer

Correct Answer : A. An integer
The second letter, i, means integer. (From Chapter 36 : MySQLi Prepared Statements, Transactions and Security)

Q32. Which function permanently saves an uploaded file?

Show Answer

Correct Answer : B. move_uploaded_file()
It moves the temporary upload to its final location. (From Chapter 14 : PHP and the File System)

Q33. What does function greet($n, $g = "Hi") mean?

Show Answer

Correct Answer : C. $g is optional with default "Hi"
A parameter with an assigned value has a default and is optional. (From Chapter 10 : User-Defined Functions)

Q34. Which method displays form data in the browser's address bar?

Show Answer

Correct Answer : C. GET
GET appends the data to the URL. (From Chapter 11 : PHP Form Handling)

Q35. How do you create a cookie that expires in one hour?

Show Answer

Correct Answer : C. setcookie("c", "v", time() + 3600)
The expiry is a Unix timestamp: now + 3600 seconds. (From Chapter 30 : State Management – Cookies and Query Strings)

Q36. Which storage engine is the default in current MySQL/MariaDB and supports transactions?

Show Answer

Correct Answer : D. InnoDB
InnoDB has been the default since MySQL 5.5. (From Chapter 32 : Database Support and MySQL Fundamentals)

Q37. Which function counts characters correctly in UTF-8 text?

Show Answer

Correct Answer : D. mb_strlen()
mb_strlen() is multibyte-aware. (From Chapter 8 : PHP and Strings)

Q38. A newly composed article is stored with:

Show Answer

Correct Answer : B. is_published = 0
It stays pending until a moderator publishes it. (From Project 1 : Project – A Mini Content Management System with PHP and MySQLi)

Q39. Which function was removed in PHP 7.0?

Show Answer

Correct Answer : C. split()
split() was one of the removed POSIX regex functions. (From Chapter 29 : String, Variable and Miscellaneous Functions)

Q40. Which block always executes after try/catch?

Show Answer

Correct Answer : A. finally
finally runs whether or not an exception occurred. (From Chapter 20 : Error and Exception Handling)

Q41. Which constant reads a variable from the query string in filter_input()?

Show Answer

Correct Answer : A. INPUT_GET
INPUT_GET refers to $_GET data. (From Chapter 21 : PHP Filters)