















































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This certification exam guide prepares candidates to develop dynamic web applications using PHP. It covers core PHP programming, object-oriented concepts, database integration, security practices, and performance optimization. Candidates gain technical skills to design, build, and maintain PHP-based applications in professional environments.
Typology: Exams
1 / 87
This page cannot be seen from the preview
Don't miss anything!
















































































Question 1. Which PHP opening tag is recommended for maximum compatibility? A) D) <%php%> Answer: A Explanation: The full php tag works on all PHP installations, while short tags (<?) may be disabled. Question 2. What is the correct way to define a constant named MAX_USERS with value 1000? A) define('MAX_USERS', 1000); B) const MAX_USERS = 1000; C) $MAX_USERS = 1000; D) both A and B are correct Answer: D Explanation: Both define() and the const keyword can create constants; const must be used at compile time. Question 3. Which magic constant returns the full path and filename of the current script? A) LINE B) FILE C) DIR D) FUNCTION Answer: B Explanation: __FILE__ contains the absolute pathname of the file where it is used.
Question 4. Which of the following is NOT a scalar data type in PHP? A) integer B) string C) array D) boolean Answer: C Explanation: Arrays are compound types; scalar types are integer, float, string, and boolean. Question 5. What does the spaceship operator (<=>) return when the left operand is greater than the right operand? A) - 1 B) 0 C) 1 D) NULL Answer: C Explanation: <=> returns 1 if left > right, 0 if equal, and - 1 if left < right. Question 6. In php.ini, which directive controls the maximum amount of memory a script may consume? A) max_execution_time B) memory_limit C) post_max_size D) upload_max_filesize Answer: B Explanation: memory_limit sets the upper bound for memory usage per script.
C) if (condition) then … end; D) if (condition) - > … close; Answer: A Explanation: The colon (:) and endif; allow embedding PHP in HTML templates. Question 10. Which PHP construct was introduced in version 8.0 to replace complex switch statements? A) match expression B) case expression C) select statement D) pattern matching Answer: A Explanation: match provides strict comparison and returns a value, improving readability. Question 11. How many times will the following loop execute?
for ($i = 0; $i < 5; $i++) { echo $i; }A) 4 B) 5 C) 6 D) 0 Answer: B Explanation: The loop runs while $i is less than 5, producing values 0‑4, i.e., five iterations. Question 12. Which statement correctly exits two nested loops at once?
A) break; B) continue; C) break 2; D) exit; Answer: C Explanation: break can accept a numeric argument indicating how many enclosing structures to exit. Question 13. What is the difference between include and require? A) include generates a fatal error on failure, require only a warning. B) require generates a fatal error on failure, include only a warning. C) Both behave identically. D) include can only be used once per script. Answer: B Explanation: require stops script execution with a fatal error if the file cannot be loaded, while include raises a warning and continues. Question 14. Which function can be used to pass an argument by reference to a user‑defined function? A) pass_by_ref() B) & before the parameter name in the function definition C) reference() D) &$var in the call only Answer: B Explanation: Prefixing a parameter with & in the function definition makes it receive the argument by reference.
A) array_slice() B) array_values() C) array_splice() D) array_filter() Answer: B Explanation: array_values() returns all the values of the input array and reindexes them numerically starting from 0. Question 18. What does array_reduce($arr, fn($carry, $item) => $carry + $item, 0) compute? A) The product of all elements B) The sum of all elements C) The maximum element D) The count of elements Answer: B Explanation: The callback adds each $item to $carry, starting from 0, yielding the total sum. Question 19. Which visibility modifier allows a property to be accessed only within the class itself and its descendants? A) public B) protected C) private D) static Answer: B Explanation: protected members are accessible inside the class and any subclass.
Question 20. In PHP OOP, what is the purpose of the final keyword when applied to a class? A) Prevents the class from being instantiated. B) Prevents the class from being extended. C) Forces all methods to be static. D) Makes all properties immutable. Answer: B Explanation: Declaring a class as final forbids inheritance; it cannot be subclassed. Question 21. Which magic method is automatically called when an object is treated as a string? A) __toString() B) __invoke() C) __get() D) __set() Answer: A Explanation: __toString() must return a string representation of the object. Question 22. How does Late Static Binding differ from self:: in static method calls? A) self:: resolves to the class where the method is defined; static:: resolves to the runtime class. B) static:: resolves to the class where the method is defined; self:: resolves to the runtime class. C) Both behave identically. D) self:: can only be used in traits. Answer: A
Answer: B Explanation: FILTER_VALIDATE_EMAIL checks the format of an email address. Question 26. In the context of CSRF protection, what does a synchronizer token pattern involve? A) Storing a token in a cookie only. B) Embedding a hidden token field in forms and validating it server‑side. C) Relying on the Referer header. D) Using HTTP Basic authentication. Answer: B Explanation: The synchronizer token pattern issues a unique token per session, sent with each request and verified. Question 27. Which superglobal contains the raw HTTP request body, useful for JSON payloads? A) $_GET B) $_POST C) php://input (accessed via file_get_contents) D) $_REQUEST Answer: C Explanation: php://input provides read‑only access to the request body, regardless of content type. Question 28. Which HTTP status code indicates that the request was successful and a new resource was created? A) 200 OK B) 201 Created
C) 202 Accepted D) 204 No Content Answer: B Explanation: 201 is the standard response for a successful POST that resulted in a new resource. Question 29. What does the json_decode() function return when the second parameter is set to true? A) An object B) An associative array C) A JSON string D) NULL on error only Answer: B Explanation: Passing true forces the JSON to be decoded into an associative array instead of an object. Question 30. Which PHP extension provides the SimpleXMLElement class for XML parsing? A) DOM B) XMLReader C) SimpleXML D) XMLWriter Answer: C Explanation: The SimpleXML extension offers a straightforward API to work with XML data. Question 31. Which function starts a new session or resumes an existing one? A) session_start() B) session_begin()
C) mysqli_stmt_prepare($stmt, $query) D) prepare_mysqli($link, $query) Answer: A Explanation: The procedural counterpart of $link->prepare() is mysqli_prepare(). Question 35. Which SQL clause is used to retrieve only distinct rows? A) UNIQUE B) DISTINCT C) ONLY D) DIFFERENT Answer: B Explanation: SELECT DISTINCT column FROM table eliminates duplicate rows. Question 36. What does the BEGIN TRANSACTION statement do in PDO? A) Starts a new connection. B) Begins a database transaction. C) Commits pending changes. D) Rolls back the last query. Answer: B Explanation: Starting a transaction groups subsequent queries so they can be committed or rolled back atomically. Question 37. Which function reads the entire contents of a file into a string? A) fread() B) file_get_contents() C) file_read_all()
D) stream_get_contents() Answer: B Explanation: file_get_contents() is a convenience wrapper that opens, reads, and closes the file. Question 38. How can you create a directory named uploads with permissions 0755? A) mkdir('uploads', 0755); B) mkdir('uploads', 0755, true); C) Both A and B are correct; B allows recursive creation. D) mkdir('uploads'); // permissions are always 0755 Answer: C Explanation: mkdir() creates a directory; the third argument enables recursive creation of nested paths. Question 39. Which stream wrapper would you use to read raw POST data? A) php://stdin B) php://input C) php://output D) php://memory Answer: B Explanation: php://input provides read‑only access to the request body, suitable for raw POST data. Question 40. Which error level indicates a serious problem that stops script execution? A) E_NOTICE B) E_WARNING C) E_ERROR
Answer: A Explanation: The loose comparison == treats null as equivalent to false. Question 44. Which operator can be used to concatenate strings in PHP? A) + B). (dot) C) :: D) => Answer: B Explanation: The dot (.) operator joins two strings. Question 45. Which of the following is the correct syntax for a namespaced class App\Controllers\HomeController? A) namespace App\Controllers; class HomeController {} B) class App\Controllers\HomeController {} C) namespace "App\Controllers"; class HomeController {} D) use App\Controllers; class HomeController {} Answer: A Explanation: namespace keyword declares the namespace, followed by the class definition. Question 46. In PHP 8, which attribute can be used to enforce that a function argument must be of type int and cannot be null? A) #[NotNull] B) #[Typed] C) #[\Attribute] D) There is no attribute; type declaration does this. Answer: D
Explanation: Declaring function foo(int $x) already enforces a non‑null integer; no attribute is needed. Question 47. Which function sanitizes a string by stripping tags? A) filter_var($str, FILTER_SANITIZE_STRING) (deprecated) B) strip_tags($str) C) html_entity_decode($str) D) htmlentities($str) Answer: B Explanation: strip_tags() removes HTML and PHP tags from a string. Question 48. Which PDO fetch mode returns each row as an associative array indexed by column name? A) PDO::FETCH_NUM B) PDO::FETCH_ASSOC C) PDO::FETCH_BOTH D) PDO::FETCH_OBJ Answer: B Explanation: PDO::FETCH_ASSOC yields associative arrays. Question 49. What does the header('Location: /login.php'); function do? A) Sends a 302 redirect to the client. B) Includes the file login.php. C) Sets a cookie named Location. D) Outputs the string "Location: /login.php". Answer: A
Question 53. Which of the following is the correct way to register an autoloader using spl_autoload_register? A) spl_autoload_register('myAutoloader'); B) spl_autoload_register(new MyAutoloader()); C) spl_autoload_register(function ($class) { require $class. '.php'; }); D) All of the above Answer: D Explanation: spl_autoload_register accepts a callable; all shown forms are valid. Question 54. Which PHP function can be used to convert an object to an associative array? A) (array) $obj B) get_object_vars($obj) C) json_decode(json_encode($obj), true) D) All of the above Answer: D Explanation: Each method yields an associative array representation of the object. Question 55. Which of the following is the correct syntax to define a class constant named VERSION with value '1.0'? A) const VERSION = '1.0'; B) define('VERSION', '1.0'); C) const self::VERSION = '1.0'; D) Both A and B are acceptable inside a class. Answer: A Explanation: Inside a class, const defines a class constant. define() creates a global constant, not a class constant.
Question 56. What does the ?? (null coalescing) operator do? A) Returns the left operand if it is not null; otherwise the right operand. B) Checks for strict equality. C) Performs a bitwise OR. D) Concatenates strings. Answer: A Explanation: ?? is a shorthand for isset($a)? $a : $b. Question 57. Which function can be used to retrieve the current script’s execution time in microseconds? A) microtime(true) B) gettimeofday() C) time() D) hrtime() Answer: A Explanation: microtime(true) returns the timestamp as a float with microsecond precision. Question 58. Which of the following is the correct way to set a cookie that expires in 30 days? A) setcookie('user', 'John', time() + 302460*60); B) setcookie('user', 'John', 30); C) setcookie('user', 'John', '+30 days'); D) setcookie('user', 'John'); // expires at end of session Answer: A Explanation: The third parameter expects a Unix timestamp; adding 30 days in seconds sets the expiration.