Consider a scenario where you need to ensure that a particular piece of code only executes once, regardless of how many times a function is called. Which PHP feature or function would you utilize?
- Singleton Pattern
- Static Variable
- sleep()
- exit()
To ensure a piece of code only executes once, you can use a static variable inside a function to keep track of whether it has already been executed.
Loading...
Related Quiz
- The filter_input_array() function is used to get multiple input values and optionally filter them in PHP.
- The main purpose of a destructor in a PHP class is to perform cleanup tasks before the object is destroyed.
- A variable declared within a function in PHP has a ______ scope.
- How do you execute a PHP script from the command line?
- How is it possible to know the number of rows returned in the result set?