Jump to content

Copying class objects


garry27

Recommended Posts

i don't 100% understand what you mean...but i will say that objects are always passed by reference...so:

 

function foobar ( $obj ) {
  $obj->test = 'New Value';
}
$a = new A();
$a->test = 'Old Value';
foobar($a);
print $a->test; //Prints 'New Value'

ok, I have a class callsed 'form' which handles/manages all the html forms stuff (or at least it will once I've repaired it). Inside a 'form' instance , I want to recreate this same instance (with whatever state it may be at the time) so that I can send it to another object.

um, don't you just want to use $this?

 

<?php
class form {
  function doit ( ) {
    $fb = new foobar();
    $fb->test($this);
  }
}
class foobar {
  function test ( $form ) {
    print $form->test;
  }
}
$f = new form();
$f->test = 'some value';
$f->doit();
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.