Complete the code to create a new instance of the class.
<?php class Car {} $myCar = [1] Car(); ?>
In PHP, you create a new object by using the new keyword followed by the class name and parentheses.
Complete the code to instantiate the class and assign it to a variable.
<?php class Dog {} $dog = [1] Dog(); echo get_class($dog); ?>
The new keyword is used to create an instance of the Dog class.
Fix the error in the code to correctly instantiate the class.
<?php class Book {} $book = [1] Book(); ?>
You must use the new keyword before the class name to create an object.
Complete the code to instantiate the class and call its method.
<?php class Person { function greet() { return "Hello!"; } } $person = [1] Person(); echo $person->greet(); ?>
Use new to create the object and -> to call its method.
Fill both blanks to instantiate the class with a constructor and access its property.
<?php class Animal { public $name; function __construct($name) { $this->name = $name; } } $animal = [1] Animal([2]); echo $animal->name; ?>
Use new to create the object, pass the name as a string, and use -> to access the property.
