Search⌘ K
AI Features

Solution Review: Classes and Objects

Explore the essentials of PHP classes and objects by reviewing class creation, adding public properties, and implementing methods. Learn to instantiate objects, assign property values, and invoke methods through practical examples.

Solution: Task 1

PHP
<?php
class User {
public $firstName;
public $lastName;
}
?>

Explanation

  • Line 2: We write the User class.
  • Line 4: We add the public property $firstName to the User class.
  • Line 5: We add the public property $lastName to the User class.

Solution: Task 2

PHP
<?php
class User {
public $firstName;
public $lastName;
public function hello() {
return "hello";
}
}
?>

Explanation

  • Line 2: We write the User class with ...