How can you determine if a variable is an array in PHP?

  • Using the is_array() function
  • Using the isArray() function
  • Using the isarray() function
  • Using the ArrayCheck() function
You can determine if a variable is an array in PHP by using the is_array() function, which returns true if the variable is an array.

How can you restrict the maximum file size for uploads in PHP through a form?

  • Using .htaccess file
  • Setting upload_max_filesize in php.ini
  • Using $_FILES['size']
  • Validating file size in PHP code
You can restrict the maximum file size for uploads in PHP through a form by setting the upload_max_filesize directive in the php.ini configuration file. This directive limits the size of uploaded files.

Which of the following data types in PHP is not scalar?

  • int
  • string
  • array
  • boolean
The non-scalar data type in PHP is an array. Arrays can hold multiple values and are not considered scalar because they are collections of values, not single values. Scalars include integers, strings, and booleans.

Consider a scenario where a user provides input that your PHP script tries to decode as JSON, but it's not valid JSON. Which function can help you identify the nature of the error?

  • json_last_error_msg()
  • json_encode()
  • json_last_error()
  • json_decode()
The json_last_error() function in PHP is used to retrieve the last JSON error that occurred during decoding. It helps identify the nature of the error.

Which keyword is used in PHP to inherit a class?

  • extends
  • inherit
  • interface
  • extends/implement
In PHP, the 'extends' keyword is used to inherit a class, allowing a new class (the child class) to inherit the properties and methods of an existing class (the parent class). This is a fundamental concept in object-oriented programming (OOP).

Which PHP function can be used to count the number of elements in an array?

  • count_elements
  • length
  • array_count
  • count
The correct function to count the number of elements in a PHP array is count. It's a versatile function that works with both indexed and associative arrays. It's an essential tool for array manipulation.

The properties and methods of a class are accessed outside the class using the ________ operator.

  • Dot (.)
  • Scope (::)
  • Arrow (->)
  • Hash (#)
In PHP, properties and methods of a class are accessed outside the class using the Arrow (->) operator, specifically for object-oriented access.

Which PHP function checks if a string is a valid JSON string?

  • json_verify()
  • json_decode()
  • json_check()
  • json_is_valid()
To check if a string is a valid JSON string in PHP, you can use the json_is_valid() function. This function returns true if the string is valid JSON and false if it's not. Using json_decode() will attempt to decode the string and return null on invalid input.

To specify that a function should return a value of a specific type, you use a ________ before the function name.

  • returntype
  • returnType
  • typehint
  • type
In PHP, to specify a function's return type, you use returnType before the function name. This is known as a "return type declaration."

You are developing a PHP web application and want to ensure that any PHP errors do not reveal sensitive information to the users. Which approach would you take?

  • a) Disable error reporting.
  • b) Enable error reporting and use custom error handlers.
  • c) Use generic error messages for all errors.
  • d) Store errors in a public log file.
b) Enabling error reporting and using custom error handlers is the recommended approach. It allows you to handle errors gracefully while not revealing sensitive information to users. Disabling error reporting (a) could make debugging difficult, using generic error messages (c) isn't best practice, and storing errors in a public log file (d) is a security risk.