What are Regular Expressions in PHP?

  • They are a sequence of characters that define a search pattern.
  • They are predefined patterns used to validate email addresses.
  • They are PHP functions used to manipulate strings.
  • They are numeric values used for mathematical calculations.
Regular expressions in PHP are a sequence of characters that define a search pattern. They are powerful tools used for pattern matching and manipulating strings. Regular expressions are based on a formal language and provide a concise and flexible way to search, extract, and manipulate text data. They can be used to validate inputs, perform string substitutions, extract data from strings, and more. Learn more: https://www.php.net/manual/en/book.regex.php

A common practice in PHP forms is to set an error variable for each field and display the error message next to the field if the ______.

  • Field value is not empty
  • Field value is empty
  • Field value is null
  • Field value is set
A common practice in PHP forms is to set an error variable for each field and display the error message next to the field if the field value is empty. This approach involves checking the value of each required field, and if any field is found to be empty when the form is submitted, you can set an error variable specific to that field. The error message can then be displayed next to the corresponding field to indicate that it is a required field and needs to be filled in. This approach provides clear and specific error messages for each required field, improving the user experience and aiding in form completion. Learn more: https://www.php.net/manual/en/tutorial.forms.php

You have a variable in your PHP script that needs to hold a simple true or false value. What data type would you use?

  • int
  • float
  • string
  • boolean
To hold a simple true or false value in PHP, you would use the boolean data type. The boolean data type is specifically designed to store either true or false values. It is commonly used in conditions, logical operations, or to indicate the success or failure of an operation. By using the boolean data type, you can ensure that the variable only holds the expected true or false values, providing clarity and correctness to your code. Learn more: https://www.php.net/manual/en/language.types.boolean.php

Once a constant is set in PHP, it cannot be ______ or ______.

  • Modified or redefined
  • Accessed or printed
  • Declared or assigned
  • Deleted or removed
Once a constant is set in PHP, it cannot be modified or redefined during the script execution. Constants are intended to store fixed values that remain constant throughout the execution of the script. Once defined, their value cannot be changed. Any attempt to modify or redefine a constant will result in an error. This behavior ensures that constants maintain their fixed value and avoid accidental changes. Learn more: https://www.php.net/manual/en/language.constants.php

What function can be used in PHP to filter and validate data?

  • filter_var()
  • validate_data()
  • sanitize_data()
  • clean_data()
In PHP, the filter_var() function is commonly used to filter and validate data. It allows you to apply various filters to sanitize and validate input data, such as filtering for specific data types, validating email addresses, sanitizing URLs, and more. The filter_var() function is a versatile tool for data validation and sanitization in PHP. For more information, refer to: http://php.net/manual/en/function.filter-var.php

The continue statement in PHP is used to ______ the current iteration of a loop and move the program control to the next iteration.

  • Skip
  • Terminate
  • Pause
  • Restart
The correct option is: "Skip." The continue statement in PHP is used to skip the remaining code in the current iteration of a loop and move the program control to the next iteration. It allows you to bypass certain iterations based on a condition. Learn more: https://www.php.net/manual/en/control-structures.continue.php

In PHP, you can define an abstract class using the abstract keyword like abstract class ClassName { ______ }.

  • public methods and properties
  • abstract methods and properties
  • private methods and properties
  • static methods and properties
In PHP, to define an abstract class, you can indeed use the abstract keyword followed by the class keyword and the name of the class. For example: abstract class ClassName { }. Within the abstract class, you can define both abstract methods (without implementation) and non-abstract methods (with implementation). Abstract methods serve as placeholders that must be implemented in the child classes that inherit from the abstract class. To learn more, see: http://php.net/manual/en/language.oop5.abstract.php

Are Parent constructors called implicitly inside a class constructor?

  • Yes
  • No
  • Depends on the scenario
  • Only in abstract classes
Parent constructors are not called implicitly inside a class constructor in PHP. You need to explicitly call the parent constructor using parent::__construct(). Learn more: http://php.net/manual/en/language.oop5.decon.php

In a PHP while loop, where is the condition tested?

  • Before each iteration
  • After each iteration
  • At the beginning of the loop
  • At the end of the loop
In a PHP while loop, the condition is tested before each iteration. Before executing the code block for each iteration, the condition is evaluated. If the condition evaluates to true, the code block will be executed. If the condition evaluates to false, the loop will be terminated, and the execution will continue with the code following the loop. The condition is checked at the beginning of each iteration to determine whether the loop should continue or not. Learn more: https://www.php.net/manual/en/control-structures.while.php

You are writing a PHP script and you need to define a constant in a class. How would you do this?

  • const CONSTANT_NAME =
  • define(CONSTANT_NAME,
  • static CONSTANT_NAME;
  • var CONSTANT_NAME;
To define a constant in a class in PHP, you can use the const keyword followed by the constant name and its value. For example: const CONSTANT_NAME = value; Constants in a class are associated with the class itself and can be accessed using the class name without the need for object instantiation. They provide a way to store values that remain constant throughout the execution of the script. Refer to: http://php.net/manual/en/language.constants.php