Recall & Review
beginner
What is a method in PHP classes?
A method is a function defined inside a class that describes behaviors or actions objects of that class can perform.Click to reveal answer
beginner
What does the <code>$this</code> keyword represent inside a PHP class method?$this refers to the current object instance that is calling the method. It allows access to the object's properties and other methods.Click to reveal answer
intermediate
How do you call a method from inside another method in the same PHP class?
Use
$this->methodName() to call another method of the same object.Click to reveal answer
intermediate
Why can't you use
$this in static methods?Static methods belong to the class itself, not to any object instance, so <code>$this</code> (which refers to an object) is not available.Click to reveal answer
beginner
Example: What will
$this->name access inside a method?It accesses the
name property of the current object instance.Click to reveal answer
Inside a PHP class method, what does
$this refer to?✗ Incorrect
$this always refers to the current object instance inside non-static methods.How do you call a method named
greet from another method in the same PHP class?✗ Incorrect
Use
$this->greet() to call a method on the current object.Can you use
$this inside a static method?✗ Incorrect
$this is not available in static methods because they belong to the class, not an object.What will
$this->property access inside a method?✗ Incorrect
$this->property accesses the property of the current object instance.Which keyword is used to refer to the current object inside a PHP class?
✗ Incorrect
$this is the keyword for the current object instance.Explain what
$this means in PHP and how it is used inside class methods.Think about how an object refers to itself.
You got /4 concepts.
Describe how to call one method from another method inside the same PHP class.
Remember how you access properties with $this->property.
You got /4 concepts.