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 3

Q1. Which function protects pages by role in the project?

Show Answer

Correct Answer : D. require_level()
It redirects users without the required level. (From Project 1 : Project – A Mini Content Management System with PHP and MySQLi)

Q2. $_REQUEST contains the contents of:

Show Answer

Correct Answer : A. $_GET, $_POST and $_COOKIE
$_REQUEST merges GET, POST and COOKIE data. (From Chapter 11 : PHP Form Handling)

Q3. E-mail header injection is prevented by:

Show Answer

Correct Answer : D. Validating fields and rejecting newlines
Injected headers need newline characters. (From Chapter 15 : PHP and E-Mail)

Q4. MVC is considered an evolution of:

Show Answer

Correct Answer : D. IPO (Input, Processing, Output)
IPO was the best-practice model of older applications. (From Chapter 19 : PHP and MVC (Model–View–Controller))

Q5. Which PHP 8 feature allows format(1234.5, prefix: "Rs. ")?

Show Answer

Correct Answer : B. Named arguments
Arguments are passed by parameter name. (From Chapter 10 : User-Defined Functions)

Q6. Which DSN type is visible to Apache running as a service?

Show Answer

Correct Answer : C. System DSN
System DSNs are available to all users and services. (From Chapter 37 : Database Support using ODBC)

Q7. PHP code is executed:

Show Answer

Correct Answer : B. On the web server
PHP is server-side; only its output reaches the browser. (From Chapter 3 : PHP – Hypertext Preprocessor: Introduction and Syntax)

Q8. Which pattern matches exactly ten digits?

Show Answer

Correct Answer : A. /^\d{10}$/
^ and $ anchor the string; \d{10} means exactly ten digits. (From Chapter 12 : Form Validation and Regular Expressions)

Q9. Which loop is designed to iterate over arrays?

Show Answer

Correct Answer : B. foreach
foreach visits each element of an array. (From Chapter 7 : Looping Statements)

Q10. Which error_log() message type appends to a file?

Show Answer

Correct Answer : A. 3
Type 3 appends the message to the destination file. (From Chapter 26 : Error, HTTP, Mail and Mathematical Functions)

Q11. What is the name of the constructor method in PHP 8?

Show Answer

Correct Answer : A. __construct()
Only __construct() is a constructor in PHP 8. (From Chapter 17 : Object-Oriented PHP – Classes and Objects)

Q12. \strlen("x") inside a namespace calls:

Show Answer

Correct Answer : B. The global strlen
A leading backslash means the global space. (From Chapter 16 : PHP Namespaces)

Q13. Which PHP 8.2 method prepares, binds and executes in one call?

Show Answer

Correct Answer : A. $conn->execute_query()
execute_query() takes the SQL and an array of values. (From Chapter 36 : MySQLi Prepared Statements, Transactions and Security)

Q14. Range limits for FILTER_VALIDATE_INT are given in an array named:

Show Answer

Correct Answer : B. "options"
Options such as min_range and max_range go in "options". (From Chapter 21 : PHP Filters)

Q15. In which PHP version was register_globals removed?

Show Answer

Correct Answer : D. 5.4
It was turned off by default in 4.2, deprecated in 5.3 and removed in 5.4. (From Chapter 4 : Constants, Variables and Data Types)

Q16. Which function is deprecated since PHP 8.1?

Show Answer

Correct Answer : C. strftime()
strftime() and gmstrftime() are deprecated. (From Chapter 24 : Date, Time and Calendar Functions)

Q17. Which loop can iterate a mysqli_result directly?

Show Answer

Correct Answer : A. foreach
mysqli_result is traversable. (From Chapter 35 : PHP and MySQLi – Object-Oriented Style)

Q18. Which superglobal stores session variables?

Show Answer

Correct Answer : C. $_SESSION
$_SESSION holds the session data. (From Chapter 31 : State Management – Sessions)

Q19. XML tags are:

Show Answer

Correct Answer : A. Defined by the author
XML has no predefined tags. (From Chapter 38 : XML with PHP)

Q20. Which classic function is equivalent to the SQL command USE?

Show Answer

Correct Answer : C. mysql_select_db()
It makes a database the active one. (From Chapter 33 : PHP and MySQL – The Classic mysql API)

Q21. Which component of the AMP stack is the web server?

Show Answer

Correct Answer : D. Apache
Apache is the HTTP (web) server; MySQL/MariaDB is the database server and PHP is the scripting language. (From Chapter 1 : AMP Basics – Apache, MySQL and PHP)

Q22. An abstract class:

Show Answer

Correct Answer : D. Cannot be instantiated
Abstract classes only serve as parents. (From Chapter 18 : Object-Oriented PHP – Abstraction, Overloading, Iteration and Patterns)

Q23. Which keyword introduces an extra condition after if?

Show Answer

Correct Answer : C. elseif
PHP uses elseif (else if also works). (From Chapter 6 : Conditional Statements)

Q24. Which operator appends a string to a variable?

Show Answer

Correct Answer : B. .=
.= is the concatenating assignment operator. (From Chapter 5 : Operators and Expressions)

Q25. empty("0") returns:

Show Answer

Correct Answer : A. true
The string "0" counts as empty. (From Chapter 29 : String, Variable and Miscellaneous Functions)

Q26. Most browsers limit a single cookie to about:

Show Answer

Correct Answer : D. 4096 bytes
Cookies are limited to roughly 4 KB. (From Chapter 30 : State Management – Cookies and Query Strings)

Q27. Which program creates Apache password files?

Show Answer

Correct Answer : D. htpasswd
htpasswd creates and updates the user file. (From Chapter 22 : .htaccess Security)

Q28. $_FILES["file"]["tmp_name"] contains:

Show Answer

Correct Answer : D. The temporary path on the server
tmp_name is the server-side temporary copy. (From Chapter 14 : PHP and the File System)

Q29. Which data type stores exact monetary values?

Show Answer

Correct Answer : C. DECIMAL
DECIMAL is exact fixed-point. (From Chapter 32 : Database Support and MySQL Fundamentals)

Q30. What does echo 'Hi\n$x'; print?

Show Answer

Correct Answer : C. Hi\n$x
Single-quoted strings neither interpret \n nor expand variables. (From Chapter 8 : PHP and Strings)

Q31. If the included file is missing, include produces a:

Show Answer

Correct Answer : D. Warning
include warns and continues. (From Chapter 13 : Server Side Includes – include and require)

Q32. rmdir() succeeds only if the directory is:

Show Answer

Correct Answer : D. Empty
Files must be removed first. (From Chapter 25 : Class/Object, Function Handling, Directory and File Functions)

Q33. The MySQLi procedural equivalent of mysql_query($sql) is:

Show Answer

Correct Answer : A. mysqli_query($link, $sql)
The connection is the first argument. (From Chapter 27 : MySQL Functions and their MySQLi Equivalents)

Q34. Who can publish articles in the project CMS?

Show Answer

Correct Answer : C. Moderators and administrators
Publishing requires the proper permissions. (From Chapter 40 : Content Management System (CMS) – Concepts)

Q35. $families['Griffin'][2] accesses an element of a:

Show Answer

Correct Answer : C. Multidimensional array
Two indexes are used: the family and the member. (From Chapter 9 : PHP and Arrays)

Q36. ip2long("192.168.1.10") returns:

Show Answer

Correct Answer : A. An integer
It converts the address into an integer. (From Chapter 28 : Network, Output Buffer, Configuration and Session Functions)

Q37. The default web root folder of XAMPP on Windows is:

Show Answer

Correct Answer : D. C:\xampp\htdocs
Files in C:\xampp\htdocs are served at http://localhost/. (From Chapter 2 : XAMPP – Installation, Configuration and Use)

Q38. A custom exception class must:

Show Answer

Correct Answer : A. Extend Exception
Custom exceptions inherit from Exception. (From Chapter 20 : Error and Exception Handling)

Q39. AJAX was originally made possible by an object first shipped in:

Show Answer

Correct Answer : C. Internet Explorer 5
XMLHttpRequest began as an ActiveX control in IE5. (From Chapter 39 : PHP and AJAX)

Q40. Which function adds elements to the beginning of an array?

Show Answer

Correct Answer : A. array_unshift()
array_unshift() prepends values. (From Chapter 23 : Apache and Array Functions)

Q41. Which fetch function lets you write $row->name?

Show Answer

Correct Answer : B. mysqli_fetch_object()
It returns the row as an object. (From Chapter 34 : PHP and MySQLi – Procedural Style)