6: Constructors and Destructors in OOP PHP | Object Oriented PHP Tutorial For Beginners | mmtuts

Поділитися
Вставка
  • Опубліковано 11 лис 2024

КОМЕНТАРІ • 130

  • @thegentofculture
    @thegentofculture 4 роки тому +12

    I just wish you had a video for every subject I want to study. You are probably the best youtube coding instructor I've ever seen. Seriously, I've been studying for years.

  • @holliegolitely6245
    @holliegolitely6245 5 місяців тому +2

    Here from the future to let you know that you did not talk too much and I understood what you said. Thank you for this series!

    • @LiteralHatReloaded
      @LiteralHatReloaded 5 місяців тому

      Yes i was just here to comment the exact same thing. its just the perfect amount needed; not redundant, but not so sparse either that you're still a bit unsure of things.

  • @lawrence744
    @lawrence744 6 місяців тому +3

    Even if you talk a lot, it makes things very clear and easy to understand. Some people might complain but I do like how you explain things. I cant wait for you to make Laravel tutorial. Please, make sure to do an example project so we can get the idea on using it for projects. Thank you

  • @shajibshafayet
    @shajibshafayet 5 років тому +4

    You are not talking a lot. Whatever you are doing is perfect. I like your tutorial very much. Best wishes.

  • @dan110024
    @dan110024 3 роки тому +3

    Gotta be the best, highest quality PHP tutorials on youtube. Subbed to patreon to then forget about just to pay it back.

  • @alextalos6141
    @alextalos6141 2 роки тому +2

    Best teacher. Don't stop.

  • @TheOneAndOnlyAhmed
    @TheOneAndOnlyAhmed 5 років тому +14

    My first programming language is Java because of that OOP concepts are easier to me to understand thank for the tutorial ❤

  • @woodzeppelin3241
    @woodzeppelin3241 3 місяці тому

    I have been thru a few OOP PHP video tutorials, and some were good, but either explained too fast, or high level over views. From what i learned from others, viewing these videos really nailed it for me. They made sense where the others were murky. Now i am ready to convert my procedural code to OOP. Thank you and great job.

  • @tripninaldo
    @tripninaldo 5 років тому +4

    Great! Now I can finally understand the use of "__contruct()"
    Thank you.

  • @muzika5001
    @muzika5001 2 роки тому

    Now watching after time again can say this is the best explanation in UA-cam regards of construct and destruct.

  • @mmelimahlobo7656
    @mmelimahlobo7656 Рік тому

    OMG your explanations are so clear,you are so helpful I am very grateful that I found your tutorials,May the Lord increase you more and more

  • @kuldimanas
    @kuldimanas 5 років тому +42

    Daniel: *making tutorials
    also Daniel: I feel like I talk a lot

  • @joejenkins9181
    @joejenkins9181 4 роки тому +1

    thanks m8, deadass, my teacher sucked at teaching me this and this series just saved my ass i love you so much

  • @ntcc2821
    @ntcc2821 Рік тому

    you really teach very wellll wow, you make sure there is no confusion

  • @xavocamboful
    @xavocamboful 4 роки тому

    This course is amazing. You explain it so well. It's sensitive to those that know php, and are struggling to get their heads around OOP. Thanks so much!

  • @Keithjo74
    @Keithjo74 5 років тому +6

    Nice and clear videos are easy to watch and learn from, Good Job.

  • @Awildjaapappeared
    @Awildjaapappeared Рік тому

    My man, you gained a subscriber. Just started php in my CS study and the OOP was optional for an advanced class. Wanted to be prepared so I'm following it and on the 6th video I can safely say I'm learning shitloads from these short and to the point videos. Keep it up

  • @Stoney_Eagle
    @Stoney_Eagle 5 років тому +6

    I use construct all the times but I never use deconstruct.
    Explained as expected 😉🤘

  • @joem1668
    @joem1668 5 років тому +6

    mmtuts back at it again with OOP PHP

  • @knotcircle2844
    @knotcircle2844 2 роки тому

    Thanks a lot for this Dani. It's now making sense for me. I wished I saw this while on uni.

  • @abhijitkarmakar9826
    @abhijitkarmakar9826 5 років тому +6

    An awsome way to teach PHP OOP, thanks mate, you are great (y)

  • @LandonHughes2
    @LandonHughes2 4 роки тому +13

    The Coding Train: Never forget *this dot*
    MMTuts: Never forget *this arrow*

  • @ScottPlude
    @ScottPlude 4 роки тому +4

    fantastic tutorials. I just signed up at patreon as well. Thanks for so much good info.

  • @TeejayArancina-v1o
    @TeejayArancina-v1o 16 днів тому +1

    Best teacher!

  • @tiagovieira6653
    @tiagovieira6653 4 роки тому +6

    If I may... You said that destruct occurs when we are done creating an object... That means that you instantiate a class then the construct runs to do the stuff we want it to do or not, and then once it's done the destruct runs... It is not like that.. Destruct run at the end of the script, and not when are are done creating the object.

  • @kyojurojigoro8677
    @kyojurojigoro8677 Рік тому

    omg i'v never thought i would enjoy oop some day thank you Brother

  • @Lyrik-Klinge
    @Lyrik-Klinge 4 роки тому

    Perfect explaination, clear voice, great examples!

  • @wadiibounenni4848
    @wadiibounenni4848 8 місяців тому +1

    Clear explantation as usual :)

  • @MathijsGroothuis
    @MathijsGroothuis 4 роки тому

    Nice video. One suggestion, is to do something with the destructor. Now the only thing I know is that it get's triggered already when the class is instantiated, but don't know what it's purpose or functionality would be.

  • @folomba
    @folomba 2 роки тому

    Thanks! Hello from Moscow!

  • @SnGrg
    @SnGrg 2 роки тому

    Tesla, Space X and now advanced PHP tutorials. Elon is the fountain of knowledge.

  • @senju31
    @senju31 3 роки тому

    Much love from Jamaica!

  • @LandonHughes2
    @LandonHughes2 4 роки тому +1

    man PHP sure has its quirks:
    calling a method with the *->* and the *$* when declaring variables/properties is definitely going to take time for me to get used to. I'm so used to the . thanks to C# and JS.

    • @liberationahead5020
      @liberationahead5020 4 роки тому

      I solved the problem with Karabiner Elements. Shortcut 1: Ctrl+. becomes -> and Shortcut 2: Cmd+. becomes => :-) But yes they should've just used a period!

  • @jasonfetterly5578
    @jasonfetterly5578 4 роки тому +8

    The destructor does not run at the same time as the constructor. Rather, it runs when the last reference to the object in question is gone, or at the end of the script.

    • @mrgyani
      @mrgyani 3 роки тому

      Yeah I was wondering, if they both get run at the same time - then how are we getting the value of the properties in the next line..

    • @codewithsheikh2805
      @codewithsheikh2805 2 роки тому

      yes i will like what i had to recheck, PHP possesses a destructor concept similar to that of other object-oriented languages, such as C++. The destructor method will be called as soon as there are no other references to a particular object, or in any order during the shutdown sequence.

  • @brett3554
    @brett3554 3 роки тому +1

    Great tutorial Danni

  • @udarasnsgm
    @udarasnsgm 3 роки тому

    Thank you very much..lessons are really interesting and very easy to understand

  • @marco114
    @marco114 4 роки тому

    thank you so much, i have been struggling with this concept.

  • @abolfazl3273
    @abolfazl3273 8 місяців тому +1

    Perfect

  • @domjag600
    @domjag600 2 роки тому

    What is the best work around to get over the limitation for overloading constructors?

  • @gacembenayad4670
    @gacembenayad4670 4 роки тому +1

    Thank you boss, we are going to be rich thanks to you. G and L

    • @cutscenes3399
      @cutscenes3399 4 роки тому

      yeah bro keep dreaming untill faceing the reality

  • @flickerspot
    @flickerspot 3 роки тому

    Thanks. Great tutorial

  • @vanhelsingx69x
    @vanhelsingx69x Рік тому

    best tutorials

  • @johnjosephnogales9193
    @johnjosephnogales9193 11 місяців тому +1

    wish for you to live a long life

  • @Bene31
    @Bene31 4 роки тому +1

    Summary for Java Devs:
    For constructors, use instead of "public ClassName(String s, int i)" in Java, "public function __construct(values)" in PHP.
    "$this" is equal to "this" in Java.
    You can extend classes in PHP just like in Java with "extends".
    "__destruct" is useless af (it just get's run after the "__construct", so.. use the "__construct" method).
    Everything else is pretty much the same, privat, public, protected etc.

  • @danielavazquez9706
    @danielavazquez9706 5 років тому +1

    Thank you so much for your videos!!

  • @Mohammed24441
    @Mohammed24441 4 роки тому +3

    I just need to mention something about scopes that will be related to object destruction. All variables in the root script are in the same scope even the included scripts will have access to declared variables of their parents. Only functions will have a different scope than the scrip scope. So, with that said, objects are destroyed when they reach the end of their scope. Like instantiating an object inside a function, it will call the object destructor at the end of the function body, of course, unless it's a static variable.

    • @daineldakwa1302
      @daineldakwa1302 Рік тому

      that was a good one thank you for the clarification.

    • @jayzee6432
      @jayzee6432 Рік тому

      what is a root script?

  • @travis-tech
    @travis-tech 3 роки тому +2

    Im learning a lot from this course. So much better then the udemy class I paid for!
    Do you cover hooks later in this course?

  • @Voughnfox
    @Voughnfox 3 роки тому

    Super Great!!!

  • @tedabrenica5277
    @tedabrenica5277 4 роки тому

    i think its better if you practices them also to end the PHP closing tags. It might help them in the future.

  • @JAM-zr6ss
    @JAM-zr6ss Рік тому

    You look like a version of Mr. BEAST and Elon Musk combined. And thanks for this series

  • @DevlogBill
    @DevlogBill 2 роки тому

    Excellent video, my only thing would be I didn't grasp the concept of destructor, I guess I will watch the video again. Other than that, I am learning loads of information, thank you.

  • @eloquent2200
    @eloquent2200 3 роки тому

    Thank you!

  • @programmingtestsandproje
    @programmingtestsandproje 3 роки тому

    thank you

  • @Denniskjellin
    @Denniskjellin 2 роки тому

    Great stuff!!!!=)

  • @MediaMartPsh
    @MediaMartPsh 4 роки тому

    @mmtute what kind of laptop you're using here? Is it Lenovo Legion?

  • @GuruPrasad-kx4zt
    @GuruPrasad-kx4zt 4 роки тому +1

    Daniel bro god bless you

  • @ademottoman962
    @ademottoman962 5 років тому +2

    hi mmtuts can you make some more new html5 videos because i need some because you are the only one who explanes very well

  • @jasonbracero3030
    @jasonbracero3030 5 років тому +1

    Hi Daniel, I just want to clarify on what will be the sense of putting public $name;
    If you will have it also in the __construct($name);
    BTW This is a way way way better series than the others 

  • @savilboy7269
    @savilboy7269 4 роки тому

    Bro thanks a lot super helpful, appreciate it

  • @goranvuletic8873
    @goranvuletic8873 2 роки тому +1

    1:32 The destructor is not executed "right after creating an object" but when the object is deleted.
    4:50 You don't have to include parethesis when you have a constructor. You only need to add them if the constructor expects any parameters, which does not need to be the case, you can define the constructor without any passing parameters.

    • @Dani_Krossing
      @Dani_Krossing  2 роки тому

      Hehe I would call it “Wrong!”, but it’s nice to know that they aren’t required 🙂

    • @Dani_Krossing
      @Dani_Krossing  2 роки тому

      And yes, the destructor is called right before the object is deleted at the end of a script.
      I am not native English speaking, so when I said “it is run at the end”, I didn’t mean at the end of the class being loaded, but when the object is no longer referenced. 🙂 I can see how it comes off wrong in the way I phrased it there.

    • @goranvuletic8873
      @goranvuletic8873 2 роки тому

      @@Dani_Krossing Despite all of that, I very much enjoy your lessons and the way you have organized them.

  • @mohamedannajar3140
    @mohamedannajar3140 4 роки тому

    Thank you alot for this tutorials

  • @user-fs2zt4tk6q
    @user-fs2zt4tk6q 3 роки тому

    Legend thank you 👊🏼

  • @subgero
    @subgero 3 роки тому

    So, this is like setters and getters?

  • @emanuelegurini
    @emanuelegurini 5 років тому +1

    fantastic!

  • @TheScooted
    @TheScooted 2 роки тому

    I do not fully got how exactly __destruct works. What exactly it destructs? all data for all objects that used this class? Or something else?
    Or it just runs after the object is done (so we can put some code there that we need to run at the objects work end) and it is destructed automatically?

  • @hacking4457
    @hacking4457 4 роки тому

    Thank u mate

  • @abiolacomputing
    @abiolacomputing Рік тому

    You such an amazing lecturer, I had taken a course from Edwin Diaz on Udemy, He taught methods, properties, get and set, constructor etc separately because of that I am able to understand the amazing life saver lecture, newbies might be struggling as you compounded all in one go. Thank you so much for your efforts

  • @sukumarsa9039
    @sukumarsa9039 5 років тому

    Just a feedback that you spoke most about what to do and how to do. But, did I miss why to do? please review.

  • @RSTao77432
    @RSTao77432 5 років тому

    I know that you Cannot Nest Classes in the general sense of the Word but can you for example Create a Class With A method, Which then has Seperate Classes inside that method. That would make what i'm trying to do a hell of a lot easier... ?

  • @MrCef1911
    @MrCef1911 5 років тому

    Could you provide an example of when you would have a PHP constructor ( _construct) using a get or post method with a HTML Form element ?

  • @ademineshat
    @ademineshat 5 років тому

    👌 Great.

  • @Redbearshit
    @Redbearshit 5 років тому

    Thank you very much! Where can I donate?

  • @mrinalsood9887
    @mrinalsood9887 2 роки тому

    Tattooed Elon Musk haha. Btw great lessons sir!!

  • @emmanuelsounyo2021
    @emmanuelsounyo2021 3 роки тому

    Hello please mine is not echoing as shown in the video is there a chance you linked up the includes file ; because am getting a feedback error on the line

    • @Dani_Krossing
      @Dani_Krossing  3 роки тому

      The video is a direct continuation of the last lessons, so yes the include file is linked at the top of the index page. As you can tell in the video, the top line in my index page is line 4 and it has the ?> in it, so there is the same PHP code as in the previous lessons 🙂

  • @ThatoJChere
    @ThatoJChere 4 роки тому

    Should i always use constructors for initialization, am asking because when i instantiate the person class the constructor expects arguments, so in the tutorial you already have Daniel his age and eye color passed as argument. Should i be initializing my instance with null values then use my regular setter method?... Say initially i want my object to have empty values...

    • @ApplicableProgramming
      @ApplicableProgramming 4 роки тому +1

      Both are valid ways of using it, the way he presents is called dependency injection, where his objects require some values/dependencies in order to be initiated properly. You can set them to null and then configure them when needed. So one is not better then the other, depends on how you need it

  • @arnelforbes5912
    @arnelforbes5912 5 років тому

    Its Great, you are using touch pad only

  • @andreabutalid1958
    @andreabutalid1958 4 роки тому

    Can I ask help what should I do for echo to show all the properties ?

    • @kvazaios5026
      @kvazaios5026 4 роки тому

      Create a method that you will return all the properties inside there and just call this method on the inddx page

    • @bhaweshthapa4672
      @bhaweshthapa4672 3 роки тому

      get_object_vars($object), an in-built PHP function

  • @jankohrasko3
    @jankohrasko3 5 років тому +1

    Is the __construct() always public? Why not private? Thanx for the video.

    • @Dani_Krossing
      @Dani_Krossing  5 років тому +1

      Try it out :) "Learning by doing"

    • @TheOneAndOnlyAhmed
      @TheOneAndOnlyAhmed 5 років тому +2

      If it private how can you set values to the variables when you make object of the class?

    • @Dani_Krossing
      @Dani_Krossing  5 років тому

      @@TheOneAndOnlyAhmed The properties are private yes, but the constructor method is public. And because we assign the properties using the method this is possible.

  • @ranasheri3822
    @ranasheri3822 4 роки тому

    Is constructor important or necessary?I mean can we work without it using oop standards?

    • @ApplicableProgramming
      @ApplicableProgramming 4 роки тому +1

      Yes, it is just a principle to help you initialize object immidiatelly after it is created. You can just call your own method if you like, constructor is there just for the convenience (standard practice)

  • @joem1668
    @joem1668 5 років тому +1

    remember me homie

  • @lucioouy
    @lucioouy 2 роки тому

    damn i understood OOP faster than procedural programming

  • @ahmaddawood9691
    @ahmaddawood9691 5 років тому

    SUPER

  • @prabu2778
    @prabu2778 4 роки тому

    What's the difference between methods and constructor?
    By both ways we can create object
    Then what's the difference?

    • @ApplicableProgramming
      @ApplicableProgramming 4 роки тому

      Technically, creating an object is done by compiler not methods and constructors. Constructor is not different from regular method, the only think is that if constructor is public, you are guaranteed that it will be called on object creation. So it would be the same as if you called:
      $myObj = new Obj();
      $myObj->myCustomConstructor();
      just that the php does $myObj->__construct() for you
      (same goes for destructor, but before object is going to be destroyed)

  • @raahimfareed
    @raahimfareed 4 роки тому

    Is that a Jin Tattoo on your right arm? (Tekken)

  • @hayatzee8830
    @hayatzee8830 2 роки тому

    Return 'Thank you';

  • @adityatondon9493
    @adityatondon9493 5 років тому +1

    Where is destruct method?

  • @pepeback
    @pepeback 5 років тому

    Better null than undefined.

  • @DanTrundle
    @DanTrundle 3 роки тому

    Just spent ages trying to figure out why my calls to the constructor weren't working.. always remember to double check where you saved your files, kids! You might be accessing an outdated version!

  • @spiderangelo
    @spiderangelo 3 роки тому

    you started saying about destruct, then jumped to something else. how to use destruct?

    • @tiagocomth3194
      @tiagocomth3194 3 роки тому

      To better understand the __destrust method:
      class A {
      protected $id;
      public function __construct($id)
      {
      $this->id = $id;
      echo "construct {$this->id}
      ";
      }
      public function __destruct()
      {
      echo "destruct {$this->id}
      ";
      }
      }
      $a = new A(1);
      echo "-------------
      ";
      $aa = new A(2);
      echo "=============
      ";
      The output content:
      construct 1
      -------------
      construct 2
      =============
      destruct 2
      destruct 1

  • @sarahla701
    @sarahla701 4 роки тому

    Dude your videos are AWESOME! i think i have a crush on u xD

  • @workupfromthesky9870
    @workupfromthesky9870 4 роки тому

    12:03 playing Jazz piano again?

    • @thegentofculture
      @thegentofculture 4 роки тому

      yeah but I have to admit I actually find his way of using hands to talk to be engaging.

  • @battleofviews638
    @battleofviews638 5 років тому

    I think descructor is called later:
    ----------------------------------------------------------------------
    Result:
    ConstructorDoeis this end?Destructor

  • @adityapaluskar
    @adityapaluskar Рік тому

    _Elon Musk_ .... come from your real channel

  • @singlebw4065
    @singlebw4065 5 років тому

    Зашёл посмотреть и что вижу: Даниель, голубой и ему 28.

  • @shresthakushal
    @shresthakushal 11 місяців тому

    Is he German ?

  • @cd78
    @cd78 5 років тому +5

    OOP is overly abstracted nonsense.

    • @belinhobeli9569
      @belinhobeli9569 5 років тому

      It kind of is.

    • @Kakaohunden
      @Kakaohunden 5 років тому

      Kind of yes, but it adds a common coding standard.

    • @cd78
      @cd78 5 років тому

      @@Kakaohunden define a common coding standard??

    • @pepeback
      @pepeback 5 років тому

      You are in the wrong place

    • @andrewemerson6662
      @andrewemerson6662 5 років тому

      gl in your future endeavors

  • @NoorsDataScience
    @NoorsDataScience 4 роки тому

    Your explanation rocks, but your multimedia sucks. Because it's highly distracting. I've found your tutorials are truly valuable, but hard to concentrate on. I'd like to thank you for your initiatives.

  • @nguyenthihang2761
    @nguyenthihang2761 5 років тому

    Your procedural course was extremely comprehensible and useful but man, this course sucks. I mean the idea is generally comprehensible but not practicle. You already have a procedural course so there's no need to use a car to explain objects. Instead just jump straight into actual coding, how and why its more efficient than procedural. Its like i have to watch a long long theory of attributes and methods of a car which has nothing to do with programming and very boring and then try to merge it into php again like how to make an sql query from a car, jesus!

    • @Dani_Krossing
      @Dani_Krossing  5 років тому

      If I go too slow for you then there are many other channels who takes less time "dumbing things down" and instead go straight to coding :)

    • @niarastikatika2904
      @niarastikatika2904 4 роки тому

      these tutorials are great. you don't know what you are saying man. so just shut your mouth

    • @amasnur79
      @amasnur79 4 роки тому +1

      For beginners like me, I appreciate very much that Daniel goes slow on the details and repeats why the coding is done certain way. It reminds me from time to time of what has been mentioned in the previous lessons, especially when I binge watch the tutorials. It also helps me to practice along with the tutorials on my own server. If you think that the lessons are slow, just fast forward, that's what the arrow buttons (or the double touch) are for.
      Daniel, keep up the good work!

  • @AxxionMarketPlace-iu6ri
    @AxxionMarketPlace-iu6ri Рік тому

    Thank you