Our First Exercise Using Object Oriented PHP Programming | OOP PHP Tutorial | Learn OOP PHP. In this PHP tutorial you will learn how to use object oriented PHP programming in a real project. The project you will create, is how to make a simple calculator in object oriented PHP programming.
➤ GET ACCESS TO MY LESSON MATERIAL HERE!
First of all, thank you for all the support you have given me!
I am really glad to have such an awesome community on my channel. It motivates me to continue creating and uploading content! So thank you!
I am now using Patreon to share improved and updated lesson material, and for a small fee you can access all the material. I have worked hard, and done my best to help you understand what I teach.
I hope you will find it helpful 🙂
Material for this lesson: https://www.patreon.com/posts/oop-php-11-16327509
Amazon Auto Links: No products found.
Notice: Undefined property: Calc::$Cal in C:xampphtdocstestoopincludescalc.inc.php on line 18
Error
< ?php class Calc{ public $num1; public $num2; public $cal; public function __construct($num1,$num2,$cal){ //gobal?? $this->num1 = $num1;
$this->num2 = $num2;
$this->cal = $cal;
}
public function calcMethod(){
switch($this->cal){ //line 18, this line
case ‘add’:
$result = $this->num1 + $this->num2;
break;
case ‘sub’:
$result = $this->num1 – $this->num2;
break;
case ‘mul’:
$result = $this->num1 * $this->num2;
break;
default:
$result = “Error”;
break;
}
return $result;
}
}
i get as output 2 what ever what i do any idea ??
Great series.
My code is returning the “Error” message and below the calculator which works just fine. Why is returning the default if the calculator is working just fine?
So… I had a quick question, I noticed you teach A LOT in all kinds of different languages. I was wondering how long it took you to be able to work with OOP php? what is the regular learning time for a programmer ?
Wow! awesome tutorial
good tutorial seems like i’m starting learning and exploring PHP oop , this make the separation of concern, reusable function if it’s needed 😀
Hey Daniel, i have one question. I noticed that we don’t need to declare $num1,$num2 and $cal in Calc class, it is going to work wihtout it. Well, why we are doing this? Is it for better understanding, readability or pest practice?
Awesome tutorials!
I have figured out the problem, I had made a mistake with the $cal variable, its okay now
wow! very nice; thanks for teaching us always
my calculator is returning an error, I tried to instead of returning an error as the default I decided to add two numbers as the default case and I noticed that its returning 0, and I dont understand why, everything seems to be in place, I even checked if the post method is working and it is, the variables are being passed down, but the switch isnt taking in the values I need your help
I do hate to pick holes but @11:38 2-1 – refresh =3 …. Or are my old eyes playing tricks?
I have a question and looked upto #11 to get answer. #12 seemed a bit off topic for my question. Both -> and :: are like . operator in Java. I now have clear understanding of the difference, thanks to you. But… what is => ? You haven’t covered it in OOP series, and… I saw them in Wordpess. Something like…. $args = array (‘theme_location’ => ‘primary’); …. is an example where menus (as page) gets located for their nature. Is that => anything similar to -> or :: ? Or is it something unrelated ? It kinda looks like (and actually is) assigning instruction. Thanks again.
Great and easy to follow.
Thanks
do you have to use __construct and __deconstruct in every class?
THanks for the video. Can you please create a fully functional Social Network in PHP, jq, javascript, ajax, or vue.js, using the MVC design pattern. Thank you