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.
- Define a class called
Person
. - Since all
Person
s are of thespecies
"Homo Sapiens"
, make that a class constant - Declare (but do not define yet) the 3 class properties
$name
,$age
and$occupation
. *They should all be *public
. - Define a class constructor which accepts exactly three arguments in the following order:
$name
,$age
,$occupation
and store them in their respective properties. - Define a method called
introduce
which accepts no arguments and returns a string of the format"Hello, my name is NAME_HERE"
- 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.) - When extraterrestrials arrive on Earth, all
Person
s are expected to greet them in exactly the same way. Therefore, define a static class method calledgreet_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.
- Object-Oriented PHP #1 - Classes, Public Properties and Methods
- Object-Oriented PHP #2 - Class Constructors and $this
- Object-Oriented PHP #3 - Class Constants and Static Methods
- Object-Oriented PHP #4 - People, people, people (Practice)
- Object-Oriented PHP #5 - Classical Inheritance
- Object-Oriented PHP #6 - Visibility
- Object-Oriented PHP #7 - The "Final" Keyword
- Object-Oriented PHP #8 - Interfaces [Advanced]
- Object-Oriented PHP #9 - Abstract Classes [Advanced]
- Object-Oriented PHP #10 - Objects on the Fly [Advanced]
You May Also Like
Similar Kata:
Stats:
Created | Jul 27, 2016 |
Published | Jul 28, 2016 |
Warriors Trained | 1517 |
Total Skips | 36 |
Total Code Submissions | 8468 |
Total Times Completed | 1287 |
PHP Completions | 1287 |
Total Stars | 17 |
% of votes with a positive feedback rating | 94% of 187 |
Total "Very Satisfied" Votes | 166 |
Total "Somewhat Satisfied" Votes | 21 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 8 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 8 kyu |