SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Changing two instances of classes

    This code works in PHP4:

    PHP Code:
     $temp $first_instance_of_class;
     
    $first_instance_of_class $second_instance_of_class;
     
    $second_instance_of_class $temp
    But it doesn't work on PHP5.

    Is there any solution. Thanks in advance.

  2. #2
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    see cloning
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've already tried using cloning like this:

    $temp = clone $first_instance_of_class;
    $first_instance_of_class = clone $second_instance_of_class;
    $second_instance_of_class = clone $temp;
    But it does't work either.

  4. #4
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why is the code not working for you. I don't think you even need cloning really:

    PHP Code:
    class {}

    $one = new t;
    $one->val 'one';

    $two = new t;
    $two->val 'two';

    /*
    var_dump($one, $two);

    object(t)#1 (1) {
      ["val"]=>
      string(3) "one"
    }
    object(t)#2 (1) {
      ["val"]=>
      string(3) "two"
    }
    */

    $temp $one;
    $one $two;
    $two $temp;

    /*
    var_dump($one, $two);

    object(t)#2 (1) {
      ["val"]=>
      string(3) "two"
    }
    object(t)#1 (1) {
      ["val"]=>
      string(3) "one"
    }

    */ 

  5. #5
    SitePoint Enthusiast mjlivelyjr's Avatar
    Join Date
    Dec 2003
    Location
    Post Falls, ID, US
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sweatje's right. Just tested that on my internal php5 server and worked fine.

    Thank god we don't have to do pointer arithmetic in PHP
    Mike Lively
    Digital Sandwich - MMM MMM Good

  6. #6
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, you' right the code above is working perfectly.

    Thank you very much for the quick response.


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
  •