How to create a copy of an object in PHP?

Within PHP 5+ objects tend to be passed by reference. In PHP 4 there're passed by value (that's the reason it had runtime pass by reference, which became deprecated).

You can use the 'clone' operator inside PHP5 to copy physical objects:


<?php
//our original object is $objectA

$objectB = clone $objectA;

?>

Also, it's just objects which are passed by reference, definitely not everything.
Share on Google Plus

About srimaster

Tech Dropper is simple, easy and newest technology source with experiments and demos. I will give you tutorials, notes, code snippets, demos using PHP, MySQL, jQuery, HTML, CSS, Ajax and Javascripts.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment