Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,851 questions

51,772 answers

573 users

How to clone an object in PHP

1 Answer

0 votes
class cl
{
    public function f() {
        echo "class method <br />";
    }
}

$obj = new cl();
$obj2 = clone $obj;

print("Original Object: (obj)<br />");
echo "<pre>";
print_r($obj);
echo "</pre>";
$obj->f();
echo "<br />";

print("Cloned Object: (obj2)<br />");
echo "<pre>";
print_r($obj2);
echo "</pre>";
$obj->f();
echo "<br />";

/*
run: 

Original Object: (obj)

cl Object
(
)

class method

Cloned Object: (obj2)

cl Object
(
)

class method 

*/

 



answered Jun 4, 2016 by avibootz

Related questions

2 answers 152 views
152 views asked Mar 13, 2022 by avibootz
2 answers 116 views
116 views asked Mar 13, 2022 by avibootz
1 answer 157 views
2 answers 162 views
3 answers 107 views
1 answer 106 views
106 views asked Mar 13, 2022 by avibootz
1 answer 92 views
...