SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 37 of 37
  1. #26
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's right. Using a reference to move the instance of Test around, both of the New classes work on the same data.

  2. #27
    SitePoint Addict
    Join Date
    May 2001
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by HarryF
    That's right. Using a reference to move the instance of Test around, both of the New classes work on the same data.

    and if a reference was not used, a copy of the object would be made and both the classes would use different data?


    -unregistered.

  3. #28
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    a copy of the object would be made and both the classes would use different data?
    Extactly so the changes made by New won't be seen by New1, without the references

  4. #29
    SitePoint Addict
    Join Date
    May 2001
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by HarryF


    Extactly so the changes made by New won't be seen by New1, without the references


    aaaaaaaah! that solves such a HUGE delimma I had about OOPs. Another question :

    1. I have passed the object into my second class. I have not refrenced it, I have just passed it.
    2. Can I destroy the object inside the second class? Woud this distrucution destroy only the copy or even the original class?? This would be a good idea to improve perfomance, wouldnt you think?

    Sorry about all these questions, but a lot of things seem to be falling into place now.

    -unregistered.

  5. #30
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad it's making sense.

    Can I destroy the object inside the second class? Woud this distrucution destroy only the copy or even the original class?? This would be a good idea to improve perfomance, wouldnt you think?
    It would only destory the copy, leaving the origional untouched. Performance-wise - may be. I'm no expert on what exactly PHP does behind the scenes but my understanding is most of the performance hit comes in creating variables (objects) in the first place.

    Destroying them is probably more important in case you're running out of memory to create new objects in. You'd have to try hard to run out of memory though within the 30 seconds a PHP script usually runs (e.g. something like parsing a large XML document into objects).

    My advice is forget performance while getting into OO - you'll lose a few milliseconds here and there in execution but gain massive amounts for $freeTime from having written reusable and maintainable code...

  6. #31
    SitePoint Addict
    Join Date
    May 2001
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    makes sense.. but i was just curious how do i destroy the copy? unset($objet) ?


    -unregistered.

  7. #32
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right now unset() is all there is. In fact it's not "destroying" as the word usually means in OOP.

    PHP 5 will have support (with destructors - the "opposite" of constructors) for this which will be good for "cleaning up". Say, for example, you have an object for a MySQL connection. In it's destructor method perhaps you place mysql_disconnect().

    When the object is unset (or however it will be done in PHP 5 - delete() I believe), the destructor method, thereby disconnecting from the database.

  8. #33
    SitePoint Addict
    Join Date
    May 2001
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    unset should do the trick then... hmmm..

    -unregistered.

  9. #34
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by HarryF
    Trouble is with PHP 5.0 all constructors will have the same name. I'm still not sure if I like that - not sure it's a real benefit - the justification is it makes rename your classes less work.
    Are you serious? I've read some on PHP 5, but haven't heard about this. I only heard that destructors all had the same name. I think this idea of same name constructors is going to cause lots of problems IMO, unless they offer some backwards compatibility.

    -Peter

  10. #35
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Ontario, Canada
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Web Hound
    $x='010000010110001101101001011001000101001001100101011010010110011101101110';
    for($i=0;$i<strlen($x);$i+=8)print(chr(bindec(substr($x,$i,8))));

  11. #36
    SitePoint Addict
    Join Date
    Aug 2002
    Location
    Ottawa, Ontario, Canada
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can we infer that we can double reference to get constructors further up the heirarchy in Zend 2.0? :)

    PHP Code:
    <?php
    class A{
      
    __constructor(){}
    }

    class 
    extends A{
      
    __constructor(){}
    }

    class 
    extends B{
      
    __constructor(){
        
    //call class A's constructor??
        
    parent::parent::__constructor();
      }
    }
    ?>
    I wonder...

    Cheers,
    Keith.

  12. #37
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Ontario, Canada
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no, I don't think so.
    what you are suggesting does not really make sense
    Web Hound
    $x='010000010110001101101001011001000101001001100101011010010110011101101110';
    for($i=0;$i<strlen($x);$i+=8)print(chr(bindec(substr($x,$i,8))));


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •