how can one copy an object with state?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lawrence

    how can one copy an object with state?

    This doesn't copy state:

    $myNewObject = $myOldObject;


    This does, but it doesn't copy:

    $myNewObject = & $myOldObject;


    If I want two objects with the same state, what do I do?
  • André Næss

    #2
    Re: how can one copy an object with state?

    lawrence:
    [color=blue]
    > This doesn't copy state:
    >
    > $myNewObject = $myOldObject;[/color]

    Yes it does.

    <?php

    class Person {
    var $name;
    var $age;
    }

    $me = new Person();
    $me->name = "André";
    $me->age = 25;

    $you = $me;
    var_dump($you);

    ?>

    Or do you mean something else by state?

    André Næss

    Comment

    Working...