Skip to content

Instantly share code, notes, and snippets.

@ilhamarrouf
Created February 27, 2017 04:12
Show Gist options
  • Save ilhamarrouf/851a4474b979751d7aadafc1f0a8a60c to your computer and use it in GitHub Desktop.
Save ilhamarrouf/851a4474b979751d7aadafc1f0a8a60c to your computer and use it in GitHub Desktop.
OOP PHP
<?php
class test
{
public $a;
private $b;
function __construct($a, $b)
{
$this->a = $a;
$this->b = $b;
}
//This cloning method
function __clone()
{
$this->a = "c";
}
}
$a = new test("ankur" , "techflirt");
$b = $a; //Copy of the object
$c = clone $a; //clone of the object
$a->a = "no Ankur";
print_r($a);
print_r($b);
print_r($c);
?>
// Result
test Object
(
[a] => no Ankur
[b:test:private] => techflirt
)
test Object
(
[a] => no Ankur
[b:test:private] => techflirt
)
test Object
(
[a] => c
[b:test:private] => techflirt
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment