Created
February 27, 2017 04:12
-
-
Save ilhamarrouf/851a4474b979751d7aadafc1f0a8a60c to your computer and use it in GitHub Desktop.
OOP PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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