It's considered good practice to keep your PHP code and HTML ________ to make the code more maintainable.

  • Separate
  • Combined
  • Nested
  • Parallel
It's good practice to keep your PHP code and HTML separate. This separation, often achieved with the Model-View-Controller (MVC) pattern, enhances code maintainability by segregating logic (PHP) from presentation (HTML).

How can you prevent a class from being inherited by another class in PHP?

  • Declare it as 'final'
  • Declare it as 'static'
  • Declare it as 'const'
  • Declare it as 'sealed'
To prevent a class from being inherited, you declare it as 'final.' The 'final' keyword indicates that the class cannot be extended by other classes.

In a scenario where you have a form with multiple checkboxes having the same name, how are the values sent to the PHP server?

  • Sent as an array
  • Sent as a string
  • Sent as individual keys
  • Sent as a JSON object
When multiple checkboxes share the same name, their values are sent to the PHP server as an array. This allows you to process multiple selections using PHP arrays.

Which superglobal should be used in PHP to access session variables?

  • $_COOKIE
  • $_GET
  • $_SESSION
  • $_GLOBALS
In PHP, the $_SESSION superglobal is used to access and manipulate session variables. Session variables store user-specific data throughout a user's interaction with the web application.

Which of the following is not a magic constant in PHP?

  • __FILE__
  • __DIR__
  • __FUNCTION__
  • __VARIABLE__
Magic constants in PHP are predefined constants, such as __FILE__, __DIR__, and __FUNCTION__, which provide information about the code's context. __VARIABLE__ is not a valid magic constant.

How do you access the second element of an indexed array named $colors?

  • $colors[1]
  • $colors[0]
  • $colors.second()
  • $colors.element(2)
In PHP, arrays are zero-indexed, so the second element of an indexed array is accessed using "$colors[1]".

Which PHP function is particularly useful for validating and filtering data coming from insecure sources?

  • filter_var()
  • isset()
  • htmlentities()
  • array_push()
The filter_var() function in PHP is particularly useful for validating and filtering data coming from insecure sources. It allows you to apply various filters, such as validating email addresses or sanitizing input, to ensure that the data is safe and adheres to the desired format.

In PHP, how can you prevent file caching when reading a file?

  • Use file_get_contents() with caching disabled
  • Use fopen() with the appropriate caching flags
  • Set appropriate headers using the header() function
  • Use readfile() with caching options
To prevent file caching when reading a file in PHP, you can set appropriate headers using the header() function. This approach instructs the client not to cache the file. Options 1 and 2 do not specifically address caching.

The practice of writing code that anticipates and gracefully handles potential issues is known as ________.

  • Exception Handling
  • Defensive Programming
  • Code Optimization
  • Bug Avoidance
Defensive Programming involves proactively addressing potential issues in code, making it more robust and error-resistant.

How can you prevent the display of PHP errors on a production website while still logging them?

  • Set display_errors to Off in PHP configuration
  • Use error_reporting(E_ALL) to suppress error display, while configuring a custom error handler for logging
  • Enable error_reporting(E_ALL) to display errors only for the admin
  • Use PHP's debug_backtrace() to hide errors from public view, while logging them
To prevent the display of PHP errors on a production website while logging them, you should configure a custom error handler to log errors and set display_errors to Off in the PHP configuration.