Constants in PHP are by default ________ (case-sensitive/case-insensitive).
- case-insensitive
- uppercase-sensitive
- lowercase-sensitive
- case-sensitive
Constants in PHP are, by default, case-sensitive. This means that constant names are distinct based on their case (e.g., "CONSTANT" and "constant" are considered different).
Consider a scenario where you need to ensure that a particular piece of code only executes once, regardless of how many times a function is called. Which PHP feature or function would you utilize?
- Singleton Pattern
- Static Variable
- sleep()
- exit()
To ensure a piece of code only executes once, you can use a static variable inside a function to keep track of whether it has already been executed.
In PHP OOP, what does the term "inheritance" mean?
- Passing properties
- Extending a class
- Object duplication
- Class encapsulation
In PHP Object-Oriented Programming, "inheritance" means extending a class to create a new class with the same properties and methods as the parent class.
You're developing a PHP application where you need to segregate classes that handle database operations and email sending. Which feature of PHP allows you to group these classes in a way that they can coexist even if they have the same class name?
- Namespaces
- Traits
- Interfaces
- Abstract Classes
Namespaces in PHP allow you to group classes and avoid naming conflicts, even if they have the same class name. This is essential for organizing code and preventing naming collisions.
You are working on an online exam portal. To ensure that the user doesn't get the same session ID even if they retake the exam, what should you do at the beginning of each exam?
- Regenerate a New Session ID
- Use Local Storage for Session Management
- Maintain the Same Session ID
- Use Cookies for Session Management
To ensure that the user gets a new session ID for each exam attempt, it's crucial to "Regenerate a New Session ID" at the beginning of each exam. This prevents session re-use and maintains exam integrity.
When a user logs out of a web application, which PHP function should be used to completely destroy a session?
- session_destroy()
- session_start()
- session_unset()
- unset($_SESSION)
The session_destroy() function is used to completely destroy a session in PHP, ensuring the user is logged out and their session data is wiped clean.
In PHP, the superglobal that can be used to get variables passed to the current script via URL parameters is ________.
- $_GET
- $_REQUEST
- $_POST
- $_SESSION
The $_GET superglobal in PHP is used to retrieve variables passed to the current script via URL parameters. It's commonly used for reading data from URLs.
Which PHP function can be used to customize the error handler?
- set_error_handler()
- custom_error_handler()
- modify_error_handler()
- handle_error()
The set_error_handler() function in PHP is used to customize the error handler. It allows you to define a custom error-handling function to manage how errors are handled in your PHP application.
Which function in PHP returns a formatted string?
- sprintf()
- printf()
- str_format()
- format_string()
The sprintf() function in PHP is used to return a formatted string. It allows you to create formatted strings using placeholders and values, similar to printf() in C.
In dynamic forms where fields can be added or removed by the user, the server-side processing in PHP should use the ________ function to ensure data integrity.
- 'isset()'
- 'array_push()'
- 'count()'
- 'filter_var()'
The correct option is 'count().' In dynamic forms, where the number of fields can change, using 'count()' helps ensure data integrity by determining how many fields have been submitted and handling them appropriately. This is important for server-side validation.