Jump to content

Recommended Posts

Posted

how can I make a copy of an wire array?

clone does not work..
 

$copies = clone $originals;

foreach($originals as $original){
	$original->title = "this is the original";
}
foreach($copies as $copy){
	$copy->title = "this is the copy";
}
foreach($originals as $original){
	echo "<br>this is the original? ".$original->title;
}
foreach($copies as $copy){
	echo "<br>this is the copy? ".$copy->title;
}

outputs this

this is the original? this is the copy
this is the original? this is the copy
this is the original? this is the copy
this is the copy? this is the copy
this is the copy? this is the copy
this is the copy? this is the copy

 

Posted

importing the wiredata to the new wire array did also not work...
so I found out, that the wire data was referenced and not cloned/copied...
this works now...

$copies = new EventArray(); //new wire array
foreach($originals as $key => $original){
    $copies[$key] = clone $originals[$key]; //cloning the wiredata does work..
}

shall I just put this into a __clone(); method in my wire array? 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...