Thank you! I've been reading/researching OOP and your video put it all together for me. I especially liked that you showed the related errors, just being familiar with those will make created solid code easier. Can't wait to check out your other videos.
Thanks for the video. Coming from a c# background I needed a refresher on php’s take on oop. Just one point, static declarations are simply shared values between different instances of the class. So you could in your constructor reference the static property, (let’s say it’s called add with default value 0), with add++. Each time an instance of that class is created, it will remember the value. You can’t do this with normal properties as they always default to their original value. Maybe php is different, but I wouldn’t have thought so.
Many thanks for the video Peter. It's always good for me to watch courses like this as a kind of refresher. I'm the type of developer that tends to forget stuff I haven't had to use over a period of time.
You are awesome dude!! I am from India and my English is not too good but how was you teaching that was totally awesome !! And the way of teaching is also too good !! Thanks a lot
Thanks for this great video. I could understand every word as your style is smooth and simple. I just wanted to know what kind of code editor you use because I see it's great. Thanks in advance.
Have been coding php for several years but it's pure joy to revisit fundamentals especially demonstrated so well. Do you also have tots on singleton, abstract, final classes?
Is there such a thing as an association relationship in PHP? Such that a classB can contain an instance of classA as a property inside of classB? What you would call containment in other OO languages such as Java or C#. If not, how could you accomplish this is PHP? Example: class A{ // properties public string $name = ""; }// end class A class B{ // properties public $obj = new A(); }// end class B
Hey Baref0ot yes you could use a factory pattern for this or a singleton. These are great questions. May I invite you to our Discord server where you can ask these types of questions to our growing community. You can also format code far better in Discord than UA-cam comments howtocodewell.net/discord
That last part was tricky, because it feels like it shoul of been parent not self, sense it was defined in the parent class, but then returned in the extended class.
i dont understand that too, i just accepted it is this way to write...i guess thats how php know its a definition belonging to classes...but good question tho
He doesn't actually explain a lot of what he's typing. $this->firstname refers to the public property firstName of the Person object (note there's only one dollar sign, at the beginning of this). And the $firstName on the right side of the equals sign is the parameter that the function receives, when you instantiate the class. So the constructor function receives a value for $firstName, and stores it in the public property with the same name. $this->firstName = $firstName;
Thank you for jumping in and answering this. You are correct. I think I will need to do a refresher course or something to explain this parts in more detail.
A question that popped to my head is that, the __construct method is a public function. Nevertheless, when the Person class was extended by the Employee class, in the __construct method for Employee, the __construct method of Person class was called statically. Shouldn't that cause an error?
Hi, I am did not understood one part: 1:04:41. You have 2 classes, none of classes have static method. When you want get smth Class usually we use echo $object->parameter of metchod, and this Employee:: calls static parameters or methods, is it right? I get lost here, why you use this syntax Emplyee::. is it because it is constant?
Excellent question. Here I am accessing the constant value from outside of the class. To do this you use CLASS_NAME:: CONSTANT To do this within the class you would use self::CONSTANT In my next PHP OOP course I will explain this better. This was a great question and I will add it to the 10k subscribe AMA. Thank you
Hi Nice video helped me alot.But i have a question in getter and setter method.My question is what is the advantage of using a member of class private if it is accessible with getter and setter instead make them all public??
Because you can control programaticly how this attribute is being manipulated. You could specify in your setter that only values greater than zero are allowed etc...if it's a public attribute you any function could access the attribute and do what ever it want with the data
What's the point of makin the variables private if you're gonna write the __$SET and __$GET methods anyway?? anybody is gonna be able to change them and get them I know that you can put certain parameters in the setter to prevent the user to set it's value to something invalid, but it's still pretty public to me
Yes this was just for demonstration purposes. Magic methods are useful when you want to apply rules to a dynamic set of properties. I don't really use them much in my day to day work.
A nice video. Anyway, I had a question on how to pass a value in the setters method so that you can access the private properties. Do you have to pass that private property (argument) in the setters method so that it can be accessed outside the scope
Hi Peter, I was just wondering is there a follow on course on your channel that takes all this on to using interfaces, traits, abstraction and maybe the odd design pattern for a particular problem? Many thanks.
@@howtocodewell No worries Peter, thanks for the response. Your videos are greatly appreciated, there's not many youtubers that explain oop php in the detail you have, I feel I understand your explanations really well.
so i tried doing: $tom = new Person('Tom' , 'abc' , 'm'); $tom -> SayHello(); it gives me an error: too few arguments supplied for SayHello, expected 3 suplied 0. i thought the entire logic behind doing all this was to avoid having to re-write name,lastname,gender everytime? ok i found the answer myself, and im keeping this comment for anyone who might run ino the same problem in the future, when you define the SayHello function in your class, u gotta keep the argument list empty cz if u don't it will expect them even if the program doesn't really need them, what i did initially was this: SayHello($name ,$lastname , $gender) { //blah; } changed it to SayHello() { //blah; } and it works now xD
Yeah that should be the case. The sayhello method shouldn't take any arguments. Perhaps something else is wrong. Feel free to post your code to pastebin and share the link so I can take a look
@@howtocodewell thank you very much for your quick answer, it was quicker than some paid UDEMY courses xD like i said, changing the arguments did work, imma like and subscribe to support ur channel xD
Hello peter, thanks for the amazing tutorial, made my concepts clear however i have one question you called return self::$bloodType? wouldnt it be parent::$bloodType? i tested both and it outputs the same result. so whats the recommended option self or parent considering your example above
self keyword is used to access the properties and methods which been declared as static whereas parent keyword is used to inherit properties/methods from parent class to child
I don't understand the point of using the magic __get() and __set() methods on the private class variables. In the previous lesson, he says that you use the private declaration to restrict variable access to within the class, which makes total sense. But then, he goes on to use these magic methods and completely overrides the reason for making them private in the first place! He's essentially made them public. I could see using these magic methods to remove the boilerplate code for writing getters and setters, but I don't understand why you're using them to expose private variables outside of the class. Am I missing a fundamental point here?
Hi Matt, no you're not missing anything and this is a great question. The magic methods all for access to the private properties. They are a quicker way to do it. Personally I don't like using them myself as they obscure the class definition. However they can be useful for setting defaults. Imagine you had serialised and unserialised an object and over time that objects class definition class has changed. In this case you may want to have a safety net to catch any properties that don't exist and set defaults.
Do you mean this '->' as in $this->name; ? The arrow symbol here is a means to access the property or method from a class. If you join our Discord server we can help with code snippets. howtocodewell.net/discord/
@@howtocodewell Thank you. Yeah I see that ' -> ' all the time in PHP and Laravel code and no idea what it means. I will definitely look into joining your site. Thank you
@@howtocodewell BTW I have to say that I really love your clear articulate speaking and teaching style. Its very conducive to absorbing and learning this material. I would love to see you do more course and especially Laravel and React
I have a new HTML/JS/CSS course coming out next week and on our Discord server I have asked which course I should do next. React is an option but I think it might end up being a PHP course due to the community responses
@@umarhasnain7369 Erm okay. Didn't know pointing something out that he can improve on next time is "abuse". You need to relax. The creator clearly read it as constructive criticism.
It's complete in the sense that I won't be adding to it but it's not complete in the sense of OOP. I'm currently developing a new course on OOP design patterns
I think it's my English accent. When I miss type something or think that I've missed typed something I say oops out of habit. Perhaps I should do a 'oops' montage video hahaha
Great tutorial. But your text is too small for iPad, mobile etc, very hard to distinguish what you are typing, your theme doesn't help, that's why VS Code is so great for tutorials. I am not criticising, it looks a great tutorial, but unfortunately the syntax is just ineligible.
@@howtocodewell No probs, like I said I'm not criticising, on the contrary, its just unfortunate because it inhibits what looks a fantastic tutorial. Thanks. 👍
Join our Discord server howtocodewell.net/discord and ask coding questions in the coding-help channel
Thank you so much for this tutorial. You have made life much easier.
Man you have no idea how clearly i am able to understand you compared to anyone else man. 101/100. Thank you!
That's great to hear! Thanks
Awesome video. I've been out of the PHP loop for a few years now and this was an excellent refresher and learning experience. Thank you!
Thanks great to hear. Enjoy
Thank you! I've been reading/researching OOP and your video put it all together for me. I especially liked that you showed the related errors, just being familiar with those will make created solid code easier. Can't wait to check out your other videos.
I'm glad you are finding these videos helpful. I've been live coding a PHP OO applications on Twitch and archiving them here on UA-cam.
Thank you for this. I am not a native English speaker yet I find this tutorial quite comprehensive. This video saves my day.
Excellent, that’s very nice to hear
Thanks for the video. Coming from a c# background I needed a refresher on php’s take on oop. Just one point, static declarations are simply shared values between different instances of the class. So you could in your constructor reference the static property, (let’s say it’s called add with default value 0), with add++. Each time an instance of that class is created, it will remember the value. You can’t do this with normal properties as they always default to their original value. Maybe php is different, but I wouldn’t have thought so.
Yes that is a great point. I'm planning to do something similar to this when updating the invoice totals per invoice item.
Many thanks for the video Peter. It's always good for me to watch courses like this as a kind of refresher. I'm the type of developer that tends to forget stuff I haven't had to use over a period of time.
Me too. I an always having to re trace my steps. I'm glad you liked it
Very good tutorials, thanks !
As the people below are saying your talking very clear and even in 1.5 speed it's like a breez.
Thank you very much. Please let me know if you have any suggestions for future videos
You are awesome dude!!
I am from India and my English is not too good but how was you teaching that was totally awesome !!
And the way of teaching is also too good !!
Thanks a lot
That's great to hear. Thank you :)
You are welcome!!
Can you upload video on one more topic !!
How can we implement all these functions and how can we use in any real project?
I'm working on something like that on Twitch twitch.tv/howtocodewell
Thank you for this. This made correction to some of my false theory.
I'm glad you found the course useful
10/10 tutorials Thank you sir *respects*
Thank you. That's great to hear
Bravo best teaching ever 🙌
Thank you
I found this very useful Tutorial
Thank you
This is really a wonderful tutorial. Thank you much!
You're very welcome!
Excellent tutorial , Thanks a lot
You are more than welcome
Good job, thank you. Subscribed.
Nice tutorial! it refreshes me a lot!.
Glad to hear that!
Thanks for this great video. I could understand every word as your style is smooth and simple. I just wanted to know what kind of code editor you use because I see it's great. Thanks in advance.
Hi, The code editor is PHPStorm
Have been coding php for several years but it's pure joy to revisit fundamentals especially demonstrated so well. Do you also have tots on singleton, abstract, final classes?
Not yet by they are on my list for future tutorials
Awesome video.
Thank you
Is there such a thing as an association relationship in PHP? Such that a classB can contain an instance of classA as a property inside of classB?
What you would call containment in other OO languages such as Java or C#.
If not, how could you accomplish this is PHP?
Example:
class A{
// properties
public string $name = "";
}// end class A
class B{
// properties
public $obj = new A();
}// end class B
Hey Baref0ot yes you could use a factory pattern for this or a singleton.
These are great questions. May I invite you to our Discord server where you can ask these types of questions to our growing community. You can also format code far better in Discord than UA-cam comments
howtocodewell.net/discord
Thank you for using CLI.
I find that it’s the best way to do it.
That last part was tricky, because it feels like it shoul of been parent not self, sense it was defined in the parent class, but then returned in the extended class.
Yep that can trip me up too.
May I know the code editor he is using in this video? Thank you
This is Phpstorm
awesome video sir
Thank you
Why in the __set and __get methods did you use the syntax $this->$name instead of $this->name, like in the other examples?
I'm not sure. Perhaps I slipped up
Why you have to type $this -> $firstName = $firstName; I don't get this part? $firstName is equal to it self?
i dont understand that too, i just accepted it is this way to write...i guess thats how php know its a definition belonging to classes...but good question tho
He doesn't actually explain a lot of what he's typing. $this->firstname refers to the public property firstName of the Person object (note there's only one dollar sign, at the beginning of this). And the $firstName on the right side of the equals sign is the parameter that the function receives, when you instantiate the class. So the constructor function receives a value for $firstName, and stores it in the public property with the same name.
$this->firstName = $firstName;
Thank you for jumping in and answering this. You are correct.
I think I will need to do a refresher course or something to explain this parts in more detail.
@@howtocodewell please do :) we would apreciatte that
A question that popped to my head is that, the __construct method is a public function. Nevertheless, when the Person class was extended by the Employee class, in the __construct method for Employee, the __construct method of Person class was called statically. Shouldn't that cause an error?
Yes I can see what you mean. This how the parent class is called and it's not done statically. You've picked on a quirk of PHP 😃
Hi, I am did not understood one part: 1:04:41. You have 2 classes, none of classes have static method.
When you want get smth Class usually we use echo $object->parameter of metchod, and this Employee:: calls static parameters or methods, is it right? I get lost here, why you use this syntax Emplyee::. is it because it is constant?
Excellent question. Here I am accessing the constant value from outside of the class. To do this you use CLASS_NAME:: CONSTANT
To do this within the class you would use self::CONSTANT
In my next PHP OOP course I will explain this better.
This was a great question and I will add it to the 10k subscribe AMA.
Thank you
Your "upps" are so cute :3
Hi Sk, I'm unsure what you mean by my 'upps' - But I will take it as a compliment 😊👍😃
@@howtocodewell "That's you making mistakes ""whoops"" " !!! :v (y) btw, carry on.
I totally get that now! Other commenters have mentioned it too. There should be a Whoops montage video of all of my "Upps, Whoops and Opps" hahaha
Peter Fisher make this haha it’ll be a laugh.
@@howtocodewell right
good job sir!!!!!
Thank you
Awesome tutorial. Can you please tell me the Color Theme you are using? Thank you.
I think this is Dracula. I prefer dark themes
@@howtocodewell Thank you. Yes I am using also Dark Themes. The one you used is very easy for the eyes. I will search for it in VS Code.
Is there anything specific you did to your terminal so it shows the PHP output as it is on your video?
No, this is the inbuilt terminal in PHPStorm
@@howtocodewell okay thanks!
So confusing can i have the example code you used please il figure it out by playing?
I don't think it's available but I will have a hunt on my old GitHub repos and check
Hi Nice video helped me alot.But i have a question in getter and setter method.My question is what is the advantage of using a member of class private if it is accessible with getter and setter instead make them all public??
Because you can control programaticly how this attribute is being manipulated. You could specify in your setter that only values greater than zero are allowed etc...if it's a public attribute you any function could access the attribute and do what ever it want with the data
@@Peeetfish Thanks Got it
Why are we calling self::$bloodType instead of parent::$bloodType from the Employee extended class?
Do you have a time code for this?
What's the point of makin the variables private if you're gonna write the __$SET and __$GET methods anyway?? anybody is gonna be able to change them and get them
I know that you can put certain parameters in the setter to prevent the user to set it's value to something invalid, but it's still pretty public to me
Yes this was just for demonstration purposes. Magic methods are useful when you want to apply rules to a dynamic set of properties. I don't really use them much in my day to day work.
@@howtocodewell oh ok thanks! by the way, I would love a more advanced tutorial on php :) like about OOP and things like that
Hey Irina, Yeah I'm planning a PHP8 series in the future. Is there anything in particular you would like me to cover?
Thank you sir..
My pleasure
A nice video. Anyway, I had a question on how to pass a value in the setters method so that you can access the private properties. Do you have to pass that private property (argument) in the setters method so that it can be accessed outside the scope
You could use a public getter.
Great Course
Thanks you Bernard
Parabéns
Thank you
Hi Peter, I was just wondering is there a follow on course on your channel that takes all this on to using interfaces, traits, abstraction and maybe the odd design pattern for a particular problem? Many thanks.
Not yet but i will add it to my ideas list
@@howtocodewell No worries Peter, thanks for the response. Your videos are greatly appreciated, there's not many youtubers that explain oop php in the detail you have, I feel I understand your explanations really well.
Thank you Justin
Great Video. Like your accent. But Oriented != OrienTATed.
Haha 😀😀👍
@@howtocodewell Just trying to be helpful. :) The video is great!! Looked all over for something like this. Cheers and great job, again.
may I know what tool you are using? Since @5:22, it showed the explanation of the errors that is easy to understand. Appreciate for your tutor :D !
thumb up and subscribed your channel !
Do you mean the editor. It's PHP Storm
@@howtocodewell thanks!
Hi! Great tutorial! May I know what code editor are you using? Thanks!
I think a code editor use is IDE PhpStorm
Sorry for not getting back to you. Yes it's PHPStorm. One of my favourite coding IDE's
Thank you for answering this. You're totally correct. It's PHPStorm 😀
@@rutera24 Thank you so much!
@@howtocodewell It's okay. Thank you so much!
so i tried doing:
$tom = new Person('Tom' , 'abc' , 'm');
$tom -> SayHello();
it gives me an error: too few arguments supplied for SayHello, expected 3 suplied 0.
i thought the entire logic behind doing all this was to avoid having to re-write name,lastname,gender everytime?
ok i found the answer myself, and im keeping this comment for anyone who might run ino the same problem in the future, when you define the SayHello function in your class, u gotta keep the argument list empty cz if u don't it will expect them even if the program doesn't really need them, what i did initially was this:
SayHello($name ,$lastname , $gender)
{
//blah;
}
changed it to
SayHello()
{
//blah;
}
and it works now xD
Yeah that should be the case. The sayhello method shouldn't take any arguments. Perhaps something else is wrong.
Feel free to post your code to pastebin and share the link so I can take a look
@@howtocodewell thank you very much for your quick answer, it was quicker than some paid UDEMY courses xD like i said, changing the arguments did work, imma like and subscribe to support ur channel xD
Construct is magic method? So I need another method to supply mana potions to it, thanks.
Done
btw which time zone and when will you start the web chat on Friday?
I'm not sure which we chat you mean?
I live stream on Twitch Tuesday and Thursday morning's at 07:00 GMT and Sunday's at 14:30 GMT
@@howtocodewell got it, thanks :D
Great tutorial! May I ask what is your code editor?
Sure. For PHP I use PHPStorm and for Python I use PyCharm
NetBeans
I used to use Netbeans i loved that editor. Have you considered PHPStorm?
@@howtocodewell nah, i hate subscription model of payment, i would like to pay once
Yes I know what you mean
Hello peter, thanks for the amazing tutorial, made my concepts clear however i have one question
you called return self::$bloodType? wouldnt it be parent::$bloodType?
i tested both and it outputs the same result. so whats the recommended option self or parent considering your example above
self keyword is used to access the properties and methods which been declared as static whereas parent keyword is used to inherit properties/methods from parent class to child
I don't understand the point of using the magic __get() and __set() methods on the private class variables. In the previous lesson, he says that you use the private declaration to restrict variable access to within the class, which makes total sense. But then, he goes on to use these magic methods and completely overrides the reason for making them private in the first place! He's essentially made them public.
I could see using these magic methods to remove the boilerplate code for writing getters and setters, but I don't understand why you're using them to expose private variables outside of the class. Am I missing a fundamental point here?
Hi Matt, no you're not missing anything and this is a great question. The magic methods all for access to the private properties. They are a quicker way to do it. Personally I don't like using them myself as they obscure the class definition.
However they can be useful for setting defaults.
Imagine you had serialised and unserialised an object and over time that objects class definition class has changed.
In this case you may want to have a safety net to catch any properties that don't exist and set defaults.
Just don’t know when to use the arrow sign? What does that mean?
Do you mean this '->' as in $this->name; ?
The arrow symbol here is a means to access the property or method from a class.
If you join our Discord server we can help with code snippets.
howtocodewell.net/discord/
@@howtocodewell Thank you. Yeah I see that ' -> ' all the time in PHP and Laravel code and no idea what it means. I will definitely look into joining your site. Thank you
@@howtocodewell BTW I have to say that I really love your clear articulate speaking and teaching style. Its very conducive to absorbing and learning this material. I would love to see you do more course and especially Laravel and React
I have a new HTML/JS/CSS course coming out next week and on our Discord server I have asked which course I should do next. React is an option but I think it might end up being a PHP course due to the community responses
Orientated != Oriented
Can I ask where you spotted this mistake please?
@@howtocodewell You say it at 0:09 :) Wonderful tutorial on OOP, one of the clearest explanations on youtube.
@@martinkrivosija9685 If it is wonderful, that why are you pointing this small mistakes?
Adore this tutorial, not abuse.
@@umarhasnain7369 Erm okay. Didn't know pointing something out that he can improve on next time is "abuse". You need to relax. The creator clearly read it as constructive criticism.
is this video complete?
It's complete in the sense that I won't be adding to it but it's not complete in the sense of OOP.
I'm currently developing a new course on OOP design patterns
Sir please provide php oop project
Do you have anything in mind?
@@howtocodewell Ticket or Hotel booking system may be the best for the learner. You can consider my idea. Thanks :)
That's a good suggestion
the best is hotel booking system
Great suggestion
You can create a new Employee with no $name , but still execute sayHello();
What's "oops" in you vocabulary? 32:20 38:56
That's me making mistakes whoops 😂
@@howtocodewell
But there were none or so it seemed.
I think it's my English accent. When I miss type something or think that I've missed typed something I say oops out of habit.
Perhaps I should do a 'oops' montage video hahaha
:))))
Perhaps someone from the community could do that hahha. I'm sure I have done this a bunch of times throughout my videos
I got a little bit of a couch->corona
I'm not sure what you mean....
@@howtocodewell me neither
🤣🤣🤣
@@howtocodewell anyway great tutorial
hello sir , i want to insert php script into mysql.. how i can do..
I'm not sure I would recommend doing that. But I guess it would be stored as a string.
Reeeeturn. Lol
Pahahaha is that how I say it. I need someone to create me a blooper reel. hahaha
@@howtocodewell This video may have saved my career though, for real. Thanks. (15 year functional coder)
@@saltplug4395 Wow really. That is great to hear. All the best! :)
Great tutorial. But your text is too small for iPad, mobile etc, very hard to distinguish what you are typing, your theme doesn't help, that's why VS Code is so great for tutorials. I am not criticising, it looks a great tutorial, but unfortunately the syntax is just ineligible.
Thank you that is some great feedback. I will take this into account for future tutorials. I appreciate you bringing this to my attention
@@howtocodewell No probs, like I said I'm not criticising, on the contrary, its just unfortunate because it inhibits what looks a fantastic tutorial. Thanks. 👍
Thank you
Peter Fisher it all looks fine and well on my iPad Pro running iOS 13. Not to sure what problems Sean is facing...
Awesome video.
Thank you