7 kyu

Object-Oriented PHP #4 - People, people, people (Practice)

Description:

Object-Oriented PHP #4 - People, people, people (Practice)

About this Kata Series

In this series, we will start off by learning the very fundamentals of object-oriented programming (commonly referred to as "OOP") and classes in PHP. We will then proceed by learning about the 3 different visibilities of class properties and methods and when to use them. After that, classical inheritance will be taught along with its perks and potential drawbacks. Finally, in the final Kata(s) in this series, more advanced OOP concepts may be taught such as interfaces and even abstract classes. Apart from the main course content, every 3 Kata or so into this Series, there will be an exercise Kata to practice on previously learned knowledge.

Lesson

Since this is a practice/revision Kata, there will be no lesson.

Task

Note: If in doubt, please refer to the first 3 Kata in this Series. In the unlikely case that a certain topic in this Task is not covered by any of the first 3 Kata in this Series, you are strongly encouraged to conduct your own research.

  1. Define a class called Person.
  2. Since all Persons are of the species "Homo Sapiens", make that a class constant
  3. Declare (but do not define yet) the 3 class properties $name, $age and $occupation. *They should all be *public.
  4. Define a class constructor which accepts exactly three arguments in the following order: $name, $age, $occupation and store them in their respective properties.
  5. Define a method called introduce which accepts no arguments and returns a string of the format "Hello, my name is NAME_HERE"
  6. Define another method called describe_job which accepts no arguments and returns a string of the format "I am currently working as a(n) OCCUPATION_HERE" (NOTE: The "a(n)" part of the string is literal which means you do not have to create conditionals to check whether "a" or "an" should be used.)
  7. When extraterrestrials arrive on Earth, all Persons are expected to greet them in exactly the same way. Therefore, define a static class method called greet_extraterrestrials which accepts an argument $species and returns a string of the format "Welcome to Planet Earth SPECIES_NAME_HERE!"

Kata in this Series

This series is now complete with a total of 10 Kata, where the first 7 Kata cover the fundamentals of OOP in PHP and the last 3 Kata cover more advanced (and perhaps less-known) OOP topics in PHP.

  1. Object-Oriented PHP #1 - Classes, Public Properties and Methods
  2. Object-Oriented PHP #2 - Class Constructors and $this
  3. Object-Oriented PHP #3 - Class Constants and Static Methods
  4. Object-Oriented PHP #4 - People, people, people (Practice)
  5. Object-Oriented PHP #5 - Classical Inheritance
  6. Object-Oriented PHP #6 - Visibility
  7. Object-Oriented PHP #7 - The "Final" Keyword
  8. Object-Oriented PHP #8 - Interfaces [Advanced]
  9. Object-Oriented PHP #9 - Abstract Classes [Advanced]
  10. Object-Oriented PHP #10 - Objects on the Fly [Advanced]

You May Also Like

Fundamentals
Tutorials
Object-oriented Programming

Stats:

CreatedJul 27, 2016
PublishedJul 28, 2016
Warriors Trained1517
Total Skips36
Total Code Submissions8468
Total Times Completed1287
PHP Completions1287
Total Stars17
% of votes with a positive feedback rating94% of 187
Total "Very Satisfied" Votes166
Total "Somewhat Satisfied" Votes21
Total "Not Satisfied" Votes0
Total Rank Assessments8
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • donaldsebleung Avatar
  • smile67 Avatar
Ad