When you don't want to handle an exception and want it to be handled by a parent catch block, you can use the ________ keyword.
- rethrow
- propagate
- throwup
- throw
The throw keyword is used to rethrow an exception that you don't want to handle in the current catch block, allowing it to be caught by a parent catch block.
To append one or more elements to the end of an array, the ________ function is used.
- array_push
- array_merge
- array_append
- array_combine
The array_push function is used to append one or more elements to the end of an array in PHP. It's a way to add elements to an existing array.
You are working on a PHP application that needs to support multiple database systems, including MySQL and SQLite. Which database access method in PHP would be best suited for this purpose?
- mysqli
- PDO (PHP Data Objects)
- mysql
- sqlsrv (SQL Server Driver)
PDO (PHP Data Objects) is the most suitable method for supporting multiple database systems. It's database-agnostic, allowing you to switch between MySQL and SQLite seamlessly.
A security vulnerability that allows attackers to inject malicious scripts into web pages viewed by other users is called ________.
- Cross-Site Scripting (XSS)
- Cross-Site Request Forgery (CSRF)
- SQL Injection
- Security Gatecrash
Cross-Site Scripting (XSS) is a common web vulnerability that allows attackers to inject malicious scripts into web pages viewed by other users.
How do you define a namespace in a PHP script?
- Using the "namespace" keyword
- Wrapping code in curly braces
- Specifying it in the file's name
- Using the "define_namespace" keyword
In PHP, you define a namespace using the "namespace" keyword, followed by the namespace name. This helps encapsulate your code into a specific namespace.
You are designing a system where various types of vehicles (like cars, bicycles, trucks) share common properties and behaviors but also have unique attributes. Which OOP principle would be most beneficial in this scenario?
- Encapsulation
- Inheritance
- Abstraction
- Polymorphism
Abstraction allows you to define common behaviors and attributes in a base class, while leaving the specific implementations to the derived classes. This fits well with the scenario described.
Imagine you're building a registration system and need to ensure that two users don't register at the exact same time with the same username. Which feature of PDO would be useful to handle this situation?
- Transactions
- Prepared Statements
- Error Handling
- Data Fetching
Using transactions with PDO allows you to perform a series of operations as a single unit. In this scenario, you can ensure that user registration and username checks are atomic.
When you want to send sensitive data, like passwords, which method is more suitable?
- POST
- GET
- PUT
- PATCH
The POST method is more suitable for sending sensitive data like passwords. It sends data in the request body, not in the URL, which enhances security.
A loop that can potentially run indefinitely if not carefully controlled is known as a(n) ________ loop.
- for
- while
- foreach
- do-while
A while loop can potentially run indefinitely if its condition never becomes false, requiring careful control.
Imagine you're building a multi-step form in PHP. At the third step, you need to access data from the first step without re-submitting the form. Which PHP feature would allow you to do this?
- Sessions
- Cookies
- Hidden Fields
- Server Variables
Using Hidden Fields allows data from a previous step to be included in the form without resubmitting, enabling continuity in a multi-step process.