What PHP function can be used to write to a file?

  • readfile()
  • file_get_contents()
  • fwrite()
  • fopen()
The fwrite() function in PHP is used to write to a file. It takes the file handle obtained from fopen() as the first argument and the content to write as the second argument. It returns the number of bytes written or false on failure.

The same function name can be used for multiple functions in the same PHP script.

  • TRUE
  • FALSE
Yes, in PHP, you can define multiple functions with the same name in the same script. This is known as function overloading. However, unlike some other programming languages, PHP does not support function overloading by differentiating functions based on the number or type of arguments. The most recently declared function with the same name will be used. Learn more: https://www.php.net/manual/en/functions.user-defined.php

Which of the following are ways to make a field required in a PHP form?

  • Using the required attribute in HTML
  • Implementing server-side validation in PHP
  • Using JavaScript to validate the field on the client-side
  • All of the above
All of the above options are ways to make a field required in a PHP form. You can use the required attribute in HTML to enforce client-side validation, ensuring that the field must be filled out before submitting the form. Implementing server-side validation in PHP allows you to check if the required field has been submitted with a value. Using JavaScript on the client-side provides an additional layer of validation to ensure the field is not left empty before submitting the form. It is recommended to use a combination of client-side and server-side validation to ensure the integrity and security of form submissions. Learn more: https://www.php.net/manual/en/tutorial.forms.php

How can you call a user-defined function in PHP using a string variable?

  • Use the call_user_func() or call_user_func_array() functions
  • Use the execute_function() or execute_user_func() functions
  • Use the invoke_function() or invoke_user_func() functions
  • Use the run_function() or run_user_func() functions
To call a user-defined function in PHP using a string variable, you can use the call_user_func() or call_user_func_array() functions. These functions allow you to invoke a callback function specified by a string name. The other mentioned options (execute_function(), execute_user_func(), invoke_function(), invoke_user_func(), run_function(), run_user_func()) are not valid PHP functions. For further information, consult the PHP documentation on call_user_func(): http://php.net/manual/en/function.call-user-func.php and call_user_func_array(): http://php.net/manual/en/function.call-user-func-array.php

PHP constants are case-_________.

  • Insensitive
  • Sensitive
  • Dependent
  • Independent
PHP constants are case-sensitive. It means that constant names are treated as case-sensitive identifiers. For example, if a constant is defined as "CONSTANT_NAME", you cannot access it as "constant_name" or "CoNsTaNt_NaMe". The constant name must match exactly with its defined case. This behavior ensures that constants are accessed consistently based on their exact names. Learn more: https://www.php.net/manual/en/language.constants.php

What is the difference between Exception::getMessage and Exception::getLine?

  • getMessage returns the error message associated with the exception, while getLine returns the line number where the exception occurred
  • getMessage returns the line number where the exception occurred, while getLine returns the error message associated with the exception
  • They both return the same information
  • They are not valid methods in the Exception class
Exception::getMessage returns the error message associated with the exception, while Exception::getLine returns the line number where the exception occurred. They provide different information about the exception. Learn more: http://php.net/manual/en/class.exception.php

The keys in a PHP associative array can be both strings and integers.

  • TRUE
  • FALSE
True. In a PHP associative array, the keys can be both strings and integers. You can explicitly assign either string or integer keys to the elements of an associative array. This flexibility allows you to associate specific values with meaningful labels or identifiers. You can access the corresponding values in the array using the associated keys. Associative arrays are widely used in PHP for organizing and retrieving data in a non-sequential manner. Learn more: https://www.php.net/manual/en/language.types.array.php#language.types.array.syntax

In PHP, you can define a constant in a class using the const keyword like const CONSTANT_NAME = ______.

  • value
  • expression
  • variable
  • string
In PHP, you can define a constant in a class using the const keyword followed by the constant name, the assignment operator =, and the desired value. For example: const CONSTANT_NAME = value; Constants are used to store values that remain the same throughout the execution of a script and cannot be changed once defined. They provide a convenient way to define and use fixed values within a class. Refer to: http://php.net/manual/en/language.constants.php

What function do you use in PHP to execute a query against a MySQL database?

  • mysqli_query()
  • mysql_query()
  • pdo_query()
  • execute_query()
In PHP, you can use the mysqli_query() function to execute a query against a MySQL database. This function takes two parameters: the connection object and the SQL query you want to execute. The SQL query can be any valid MySQL statement, such as SELECT, INSERT, UPDATE, or DELETE. The mysqli_query() function returns a result object for successful SELECT queries or a boolean value for other types of queries. It's important to use prepared statements or proper escaping techniques to prevent SQL injection vulnerabilities when executing user-supplied data as part of the query.

To access data from the $_SERVER superglobal in PHP, you can use $_SERVER['element'] where 'element' is the name of the ______ you wish to access.

  • Key
  • Index
  • Element
  • Property
To access specific data from the $_SERVER superglobal array in PHP, you can use the $_SERVER['element'] syntax. Here, 'element' refers to the specific key or index of the information you want to access. For example, $_SERVER['REQUEST_METHOD'] retrieves the HTTP request method used to access the current script. By using the correct key or index, you can retrieve the desired information from the $_SERVER array. Learn more: https://www.php.net/manual/en/reserved.variables.server.php