In PHP, a callback function is a function that is passed as an argument to another function.

  • Another function
  • A class method
  • An event handler function
  • All of the above
In PHP, a callback function is a function that is passed as an argument to another function. This allows the receiving function to call the callback function at a later point in the code. Callback functions are commonly used in PHP for various purposes, such as event handling, dynamic function invocation, and more. The correct option is "Another function" as it covers the general use case of callback functions in PHP. For further information, consult the PHP documentation on callback functions: http://php.net/manual/en/language.types.callable.php

What is the main purpose of a constructor in a PHP class?

  • To initialize object properties
  • To define class methods
  • To create objects from the class
  • To access class constants
The main purpose of a constructor in a PHP class is to initialize the object's properties or perform other setup tasks when an object is instantiated from the class. The correct option is "To initialize object properties." The constructor allows you to provide initial values to the object's properties or perform necessary operations before the object is used. For more information, consult the PHP documentation on constructors: http://php.net/manual/en/language.oop5.decon.php

A constant in a PHP class is defined using the const keyword.

  • TRUE
  • FALSE
  • nan
  • nan
A constant in a PHP class is indeed defined using the const keyword. It allows you to define a constant within a class by specifying 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

You have a PHP script and you need to include a file, but you want to continue execution of the script even if the file is not found. Which statement would you use and why?

  • include()
  • require()
  • include_once()
  • require_once()
To include a file in your PHP script and continue execution even if the file is not found, you would use the include() statement. If the file is not found, a warning will be generated, but the script execution will continue without causing a fatal error.

In PHP, $_GET is a superglobal array that is used to collect data sent in the URL's ______.

  • Query string
  • Request body
  • Path parameters
  • Headers
In PHP, the $_GET superglobal is used to collect data sent in the URL's query string. When data is sent to the server through the URL using the GET method, the values are appended to the URL as key-value pairs in the query string. The $_GET superglobal allows access to these values by using the corresponding key as an index. It is commonly used to retrieve parameters or values passed through the URL. Learn more: https://www.php.net/manual/en/reserved.variables.get.php

A static method in PHP OOP is a method that belongs to the class itself rather than an instance of the class.

  • TRUE
  • FALSE
  • nan
  • nan
A static method in PHP OOP is a method that belongs to the class itself rather than an instance of the class. It can be accessed using the class name without creating an object of the class.

You need to store a price, which includes cents, in a variable in your PHP script. What type of number would you use and why?

  • float
  • integer
  • string
  • boolean
In this case, you would use the float data type to store a price that includes cents in a variable in your PHP script. The float data type allows for the representation of real numbers with a decimal point, which is suitable for storing prices that may have fractional values, such as cents. Integer data type is not suitable as it does not allow for decimal points. String data type could be used, but it is more appropriate to use float to perform arithmetic calculations if needed. Learn more: https://www.php.net/manual/en/language.types.float.php

To sanitize a string in PHP, you can use the filter_var() function with the FILTER_SANITIZE_STRING ______.

  • filter
  • sanitize
  • validate
  • clean
To sanitize a string in PHP, you can use the filter_var() function with the FILTER_SANITIZE_STRING flag. This flag specifically sanitizes the string by removing HTML tags and encoding special characters to make the string safe for output. The filter_var() function provides an easy and efficient way to sanitize strings in PHP. For more details, see: http://php.net/manual/en/function.filter-var.php

OOP in PHP stands for Object-Oriented ______.

  • Programming
  • Protocol
  • Parsing
  • Processing
In the context of PHP, OOP stands for Object-Oriented Programming. It is a programming paradigm that focuses on creating objects and defining their behavior using classes, inheritance, encapsulation, and polymorphism. The correct option is "Programming." For further details, refer to the PHP documentation on object-oriented programming: http://php.net/manual/en/language.oop5.php

You need to validate and sanitize data in your PHP script. How would you do this?

  • filter_var()
  • validate_data()
  • sanitize_data()
  • clean_data()
To validate and sanitize data in PHP, you can use the filter_var() function. This function provides a range of predefined filters to validate and sanitize different types of data, such as URLs, email addresses, numbers, and more. By applying appropriate filters, the filter_var() function helps ensure the integrity, security, and cleanliness of the data. For more details, refer to: http://php.net/manual/en/function.filter-var.php