note 118877 added to language.oop5.cloning
| From: | fabio at naoimporta dot com | Date: | Sun, 21 Feb 2016 21:54:01 +0000 |
| Subject: | note 118877 added to language.oop5.cloning | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-205001@lists.php.net to get a copy of this message | ||
It's possible to know how many clones have been created of a object. I'm think that is
correct:
<?php
class Classe {
public static $howManyClones = 0;
public function __clone() {
++static::$howManyClones;
}
public static function howManyClones() {
return static::$howManyClones;
}
public function __destruct() {
--static::$howManyClones;
}
}
$a = new Classe;
$b = clone $a;
$c = clone $b;
$d = clone $c;
echo 'Clones:' . Classe::howManyClones() . PHP_EOL;
unset($d);
echo 'Clones:' . Classe::howManyClones() . PHP_EOL;
----
Server IP: 72.52.91.14
Probable Submitter: 177.17.135.149
----
Manual Page -- http://php.net/manual/en/language.oop5.cloning.php
Edit -- https://master.php.net/note/edit/118877
Del: integrated -- https://master.php.net/note/delete/118877/integrated
Del: useless -- https://master.php.net/note/delete/118877/useless
Del: bad code -- https://master.php.net/note/delete/118877/bad+code
Del: spam -- https://master.php.net/note/delete/118877/spam
Del: non-english -- https://master.php.net/note/delete/118877/non-english
Del: in docs -- https://master.php.net/note/delete/118877/in+docs
Del: other reasons-- https://master.php.net/note/delete/118877
Reject -- https://master.php.net/note/reject/118877
Search -- https://master.php.net/manage/user-notes.php