Php Classes (Object Oriented Php 2021)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
object-oriented PHP begins with classes classes are synonymous with blueprints or templates classes are not supposed to be specifics for example we could create a post class and we could give our post class a title a description and the ability to be able to be created by a user and we would have to make this a function because of this behavior notice that we do not specify the specific title or the specific description within our post class instead we create a blueprint a template something where we can create multiple posts around a class a rule of thumb or common familiar knowledge when creating our classes we should be looking for nouns why should we be looking for marrows well in the real world let's take the example of a boat a boat can turn speed up slow down and even if you're having a really bad day sink the boat is what turns the boat has the ability to speed up the boat has the capability of slowing down and on a really really bad day the boat is what sinks we find the noun and we name our class based on and now in this case the noun is boat so we create a boat class another example would be a directory a directory can be moved or we can move a directory a directory can count its files or count files of that directory a directory can calculate its size or how many bits it has these are all things that we could possibly do with the directory but directories are now so we create a directory class let's go over a few more quick examples let's say you want to create a blog so we create a blog class in that blog has several posts while posting itself is a blueprint as we went over earlier as title description and can be created by a user so we create a post class and how cool would it be if we could give the user the capability or ability to comment on a post and just like blog or post it is its own complex blueprint or structured comment it's its own complex imprint or structure or template that we want to create many specific instances of so we create the common class now let's narrow in on our post class and let's just look at it really quickly so earlier we created the public title we created in a description and we created a function or behavior on our post class that says okay a post is created by a user I want to take a second to look at the public keyword on our post class so public is what is known as a modifier or an access there are three types of accessors there is public anything can access this there is protected this title when protected can only be accessed internally or using this title because it knew up a post new post and say okay here's our new post post object equals new post we couldn't say post object title then we'll air out on us see how that has a red squiggly blowit well that's because we have protected the title it is only accessible internally but if this is public we can access it outside of the class and we can do title equals cool article or post title the difference between protected and private would be this private is only accessible within the class itself of end the practice private can be accessed using this and so can protect it neither can be accessed externally new description like that they'll both air out so protecting the private you cannot directly access them publicly or externally from the class but you can access both protected private within the class within the functions of the class so what's the difference between protected and private let's say we created a new child class of our post class and we called it I don't know video posts and we just said okay public function and then we just did created by again or the sake of maintaining this example and we said okay this title equals hello world or video post this description equals video polish well it won't give us the red squiggly lines and we actually need to extend post it will give us the rest wiggly worms notice that this title is able to be set this description is not equal to be set the difference between protected and private is this they are both accessible internally to the class using this where private or protected is initially defined however when you extend that class to a child class video post is the child class of the post class then private is not accessible the child class will extend the protected properties and protected methods the child class will not extend the private properties or private methods if we were to change this to private so that is the difference between the private protected in public modifiers or accesses next we will be getting on to objects so guys if this was useful if this was easy to follow and understandable like a subscribe and in the next example we will be moving on to objects instances constructors and just creating objects from our classes creating instances or implementations from our blueprints so thanks again guys [Music]
Info
Channel: Clean Code Studio
Views: 1,709
Rating: undefined out of 5
Keywords: Object Oriented PHP, PHP Programming, OOP PHP, Object Oriented Programming PHP, PHP Video Tutorial, Learn PHP, PHP (Programming Language), Object-oriented Programming (Programming Language Paradigm)
Id: kwVLTxl1iZI
Channel Id: undefined
Length: 8min 22sec (502 seconds)
Published: Mon Jan 20 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.