How can multiple objects of a class be instantiated in PHP?
To instantiate multiple objects of a class in PHP, you can simply create new instances of the class using the `new` keyword multiple times. Each new instance will be a separate object with its own set of properties and methods.
class MyClass {
public $name;
public function __construct($name) {
$this->name = $name;
}
}
// Instantiate multiple objects of MyClass
$object1 = new MyClass('Object 1');
$object2 = new MyClass('Object 2');
$object3 = new MyClass('Object 3');
Keywords
Related Questions
- Are there any best practices for efficiently managing user activity tracking in PHP applications to avoid resource-intensive operations?
- What is the purpose of using the concatenation operator (.) in PHP code, as seen in the forum thread?
- How can PHP developers ensure that session_start() is called before any HTML output to avoid errors?