Once a constant is defined in PHP, can its value be changed later in the script?

  • Yes
  • No
  • Only within functions
  • Only within classes
In PHP, once a constant is defined, its value cannot be changed later in the script. Constants are intended to hold values that do not change during the script's execution.

Imagine you are creating a login system for a web application. To ensure the security of user credentials, which of the following methods would be the best practice?

  • Use HTTPS with Secure Cookies
  • Store Passwords in Plain Text Files
  • Apply Weak Encryption
  • Implementing User-Friendly Passwords
Using HTTPS with secure cookies ensures data transmission security, protecting user credentials. Storing passwords in plain text files is highly insecure. Weak encryption is also insufficient. User-friendly passwords, while a good practice, do not directly ensure security; the infrastructure does.

If a transaction encounters an issue and needs to be terminated without saving the changes, it should be ________.

  • Rolled Back
  • Committed
  • Saved
  • Isolated
To terminate a transaction without saving any changes, you should use the 'Rollback' operation. This undoes all changes made within the transaction, ensuring data consistency and integrity. 'Committed' is the opposite, indicating that the changes should be saved.

When uploading a file in PHP, which array key of the $_FILES superglobal gives the temporary location of the uploaded file?

  • tmp_name
  • name
  • temp_location
  • uploaded_file
The 'tmp_name' key in the $_FILES superglobal array contains the temporary location of the uploaded file on the server. This is important for processing and moving the file.

In the context of password hashing in PHP, what does "salting" mean?

  • Adding salt to food
  • Increasing the password length
  • Mixing a unique value with the password
  • Encrypting the password using SHA-256
"Salting" in password hashing involves mixing a unique value with the user's password before hashing to enhance security and prevent rainbow table attacks.

In the context of form validation, what does the term "sanitization" refer to?

  • Removing malicious code
  • Validating user credentials
  • Cleaning and formatting data
  • Authenticating the user
Sanitization in form validation involves cleaning and formatting user input data to remove harmful or unwanted characters, ensuring it's safe for processing.

Consider a scenario where you're building a CMS and you want to log errors to a specific file. Which PHP functions would be most suitable to open and write to this file?

  • fopen() and fwrite()
  • readfile() and copy()
  • file_get_contents() and file_put_contents()
  • file() and fwrite()
To open and write to a specific file in PHP, you should use fopen() to open the file and fwrite() to write to it. These functions offer fine-grained control over file handling, crucial for logging errors.

What is the primary difference between "overloading" and "overriding" in PHP OOP?

  • Overloading is used to create multiple methods with the same name but different parameters.
  • Overriding is used to create multiple methods with the same name but different parameters.
  • Overloading allows you to define a new class that inherits from an existing class.
  • Overriding allows you to create a new class that inherits from an existing class.
Overloading is about using the same method name with different parameters within the same class, while overriding is about providing a new implementation of a method in a child class.

In a multidimensional array, the ________ function can be used to count the total number of elements.

  • count
  • size
  • total_elements
  • array_length
To count the total number of elements in a multidimensional array, you can use the 'count' function in PHP. It counts all elements, including those within nested arrays.

Which HTTP method appends form-data into the URL in name/value pairs?

  • GET
  • POST
  • PUT
  • DELETE
The GET method appends form data into the URL as name/value pairs. This makes the data visible in the URL, which is suitable for non-sensitive information.