




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1. What is the primary purpose of the 'phpinfo()' function in PHP? A) To display server configuration information and PHP settings B) To execute a PHP script from a file C) To generate a PHP error report D) To initialize a PHP session Answer: A Explanation: The 'phpinfo()' function outputs information about PHP's configuration, including server details, loaded modules, and environment settings, aiding in debugging and configuration verification. Question 2. Which data type in PHP is used to store a sequence of characters? A) Integer B) String C) Boolean D) Array Answer: B Explanation: The string data type holds sequences of characters, used for text manipulation and storage. Question 3. How do you declare a constant in PHP?
A) define('CONSTANT_NAME', 'value'); B) const CONSTANT_NAME = 'value'; C) const CONSTANT_NAME = 'value'; D) Both A and B are correct Answer: D Explanation: PHP supports declaring constants using 'define()' function and 'const' keyword; both are valid depending on context. Question 4. Which operator is used for string concatenation in PHP? A) '.' B) '+' C) '&&' D) '||' Answer: A Explanation: The '.' operator concatenates strings in PHP, joining multiple string values into one. Question 5. What is the purpose of the 'switch' statement in PHP? A) To execute multiple statements based on different conditions B) To replace multiple 'if-else' statements for value matching C) To iterate over arrays
Answer: A Explanation: 'include' issues a warning if the file cannot be included, but the script continues; 'require' causes a fatal error, stopping script execution. Question 8. How does namespace declaration help in PHP? A) It allows organizing code and avoiding name conflicts B) It improves script execution speed C) It encrypts class names for security D) It replaces the need for autoloading Answer: A Explanation: Namespaces organize code into logical groups and prevent naming conflicts between classes, functions, or constants. Question 9. Which PHP feature allows defining a function without a name? A) Named function B) Closure (anonymous function) C) Static method D) Class method Answer: B
Explanation: Closures are anonymous functions assigned to variables, enabling inline function definitions. Question 10. How can you pass an argument by reference to a function in PHP? A) By value by default B) Prepend '&' to the argument in the function declaration C) Use 'ref' keyword before argument D) Arguments cannot be passed by reference in PHP Answer: B Explanation: Using '&' before a parameter in the function declaration passes the argument by reference, allowing modifications within the function. Question 11. Which PHP array function returns all the keys of an array? A) array_keys() B) array_values() C) array_search() D) in_array() Answer: A Explanation: 'array_keys()' retrieves all the keys from an array, useful for key-based operations.
B) preg_replace() C) substr_replace() D) explode() Answer: B Explanation: 'preg_replace()' performs pattern matching with regular expressions to replace parts of strings. Question 15. What does the 'explode()' function do in PHP? A) Converts a string into an array based on a delimiter B) Joins array elements into a string C) Replaces parts of a string based on a pattern D) Finds the position of a substring within a string Answer: A Explanation: 'explode()' splits a string into an array using a specified delimiter. Question 16. How do you declare a class in PHP? A) class ClassName {} B) function ClassName {} C) object ClassName {} D) define ClassName {}
Answer: A Explanation: The 'class' keyword is used to declare a class, encapsulating properties and methods. Question 17. Which keyword is used to access a parent class's method from a child class? A) parent B) self C) static D) this Answer: A Explanation: The 'parent' keyword calls a method or accesses a property from the parent class. Question 18. Which magic method is invoked when an object is converted to a string? A) __toString B) __clone C) __call D) __sleep Answer: A
Question 21. Which interface method must be implemented in a class that implements the 'Countable' interface? A) count() B) getCount() C) length() D) total() Answer: A Explanation: The 'Countable' interface requires the 'count()' method, which returns the number of items. Question 22. Which PHP extension is commonly used for database abstraction and supports multiple database types? A) PDO B) MySQLi C) SQLite D) ODBC Answer: A Explanation: PDO (PHP Data Objects) provides a consistent interface for accessing multiple databases. Question 23. How do prepared statements prevent SQL injection? A) By sanitizing user input automatically
B) By separating SQL code from data parameters C) By encrypting SQL queries D) By executing queries only once Answer: B Explanation: Prepared statements separate SQL code from data, preventing malicious data from being executed as code. Question 24. Which SQL statement is used to modify data in a database? A) UPDATE B) SELECT C) INSERT D) DELETE Answer: A Explanation: 'UPDATE' modifies existing records in a table. Question 25. Which NoSQL database type is optimized for key-value storage? A) Redis B) MongoDB C) Cassandra D) CouchDB
Explanation: XSS involves injecting malicious scripts into web pages, which execute in other users' browsers. Question 28. Which PHP function hashes passwords securely? A) password_hash() B) md5() C) sha1() D) hash() Answer: A Explanation: 'password_hash()' applies a secure hashing algorithm suitable for storing passwords. Question 29. Which HTTP method is used to create a new resource via a REST API? A) POST B) GET C) PUT D) DELETE Answer: A Explanation: 'POST' is used to submit data to create a new resource on the server.
Question 30. Which cookie attribute ensures that a cookie is only transmitted over secure HTTPS connections? A) Secure B) HttpOnly C) Path D) Domain Answer: A Explanation: The 'Secure' attribute indicates that the cookie should only be sent over HTTPS, enhancing security. Question 31. Which statement best describes the purpose of unit testing? A) To verify individual units of code function correctly B) To test entire applications in integration C) To test the user interface D) To perform load testing on servers Answer: A Explanation: Unit testing focuses on verifying that individual functions or components behave as expected. Question 32. Which framework is commonly used in PHP for unit testing? A) PHPUnit
Answer: A Explanation: 'require_once' includes the specified file only once, preventing duplicate definitions. Question 35. Which PHP superglobal contains data sent via HTTP POST method? A) $_GET B) $_POST C) $_REQUEST D) $_SESSION Answer: B Explanation: '$_POST' contains data submitted through HTTP POST requests. Question 36. How can you start a session in PHP? A) session_start(); B) start_session(); C) init_session(); D) begin_session(); Answer: A Explanation: 'session_start()' initializes a session or resumes an existing one, enabling session variables.
Question 37. Which function is used to set a cookie in PHP? A) setcookie() B) cookie() C) create_cookie() D) store_cookie() Answer: A Explanation: 'setcookie()' sends an HTTP header to set a cookie on the client's browser. Question 38. Which error reporting level in PHP displays all errors including notices? A) E_ALL B) E_ERROR C) E_WARNING D) E_NOTICE Answer: A Explanation: 'E_ALL' includes all error types, providing comprehensive error reporting. Question 39. How do you handle exceptions in PHP? A) Using try { } catch (Exception $e) { }
D) Disk cache Answer: A Explanation: APCu stores data in shared memory, enabling rapid access for caching purposes. Question 42. What is the purpose of 'TDD' in software development? A) To write tests before implementing code B) To test code after development C) To automate deployment D) To perform performance testing Answer: A Explanation: Test-Driven Development (TDD) emphasizes writing tests prior to coding, ensuring code correctness from start. Question 43. Which SQL clause is used to filter records based on aggregate functions? A) HAVING B) WHERE C) GROUP BY D) ORDER BY Answer: A
Explanation: 'HAVING' filters grouped records based on aggregate function results. Question 44. Which PHP function is used to decode JSON data? A) json_decode() B) json_encode() C) serialize() D) unserialize() Answer: A Explanation: 'json_decode()' converts JSON string into PHP data structures. Question 45. Which security measure involves verifying a user's identity before granting access? A) Authentication B) Authorization C) Encryption D) Sanitization Answer: A Explanation: Authentication confirms a user's identity, typically through login credentials.