Did you know FaceySpacey is the creator of Redux-First Router and Universal?

The Startup Incubator.
Your one stop social media shop
Resource Categories:

Technical
Non-Technical
Refer A Friend
Popular Articles
DEVELOPMENT TOOLS 1 - VERSION CONTROL (Mercurial)
CONTRACTING 2 - TOP 10 EASY SITE CREATOR TOOLS
Subscribe
-
Technical
-
PHP
-
OOP PHP 1 - INTRO TO OBJECT ORIENTED PROGRAMMING IN PHP OOP PHP 2 - OBJECT METHODS (AKA FUNCTIONS) OOP PHP 3 - INHERITANCE IN OOP PHP 1 - Introduction To Programming PHP 2 - DYNAMIC CODE PATHS & VARIABLES PHP 3 - FUNCTIONS PHP 4 - SCOPE PHP 5 - HOW TO LEARN PROGRAMMING PHP 6 - ARRAYS PHP 7 - LOOPS PHP 8 - CONCLUSION & MORE LEARNING TECHNIQUES
- OOP PHP 3 - INHERITANCE IN OOP
OOP PHP 3 - INHERITANCE IN OOP
And actually there is one last thing worth learning now about OOP. You can make new classes that inherit from another class. Check this code:
class BlogEntry extends Entry { public function exageratePageCount() { echo $this->pageCount + 20; } }
Notice how the "pageCount" property is not defined in the BlogEntry class. It's because it's inherited from the Entry class. Now let’s rebuild $article 1, but from the BlogEntry class/template instead, and execute this new method:
$article1 = new BlogEntry; $article1->title = ‘The Bible’; $article1->pageCount = 100; echo $article1->exageratePageCount();
Now the browser reads that it has 120 pages. The idea is so damn simple: objects instantiated/generated from the BlogEntry class have access to all the properties and methods from the parent class, Entry. Therefore you can write a reduced amount of code when you want to create similar classes. point blank period. Again, don’t worry too much about inheritance yet. It’s a feature you’ll use a lot, but a very simple one to code up and make use of. You’ll know when you need to use it to not have to write redundant code.
Super final note on OOP: visualize all this OOP stuff as simulating a world in programming. The idea is to make coding more human-like, more like the real world. I.e. classes can have children and parent classes, just like humans can have real children and real parents. Later on you’ll learn even more ways objects can work together, just as objects and organisms in the real world can. But I’m not covering that in this book. Look out for the terms “aggregation” and “composition”--they are techniques to make objects work together to create re-usable code and efficient solutions. For now inheritance is the code reuse technique we’ll leave you on. Don’t plan on abusing it ;).
Related Entries
- OOP PHP 1 - INTRO TO OBJECT ORIENTED PROGRAMMING IN PHP
- OOP PHP 2 - OBJECT METHODS (AKA FUNCTIONS)
- OOP PHP 3 - INHERITANCE IN OOP
- PHP 1 - Introduction To Programming
- PHP 2 - DYNAMIC CODE PATHS & VARIABLES
- PHP 3 - FUNCTIONS
- PHP 4 - SCOPE
- PHP 5 - HOW TO LEARN PROGRAMMING
- PHP 6 - ARRAYS
- PHP 7 - LOOPS
- PHP 8 - CONCLUSION & MORE LEARNING TECHNIQUES
Comments

SMM 3 - FORMULA TO FIND INFLUENCERS