diff options
author | DanielCiochiu <daniel@ciochiu.ro> | 2017-11-07 07:30:34 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2017-11-15 23:00:26 +0100 |
commit | dba5a798a28482ce4a6475cc4de1586f11126175 (patch) | |
tree | 041948a5096661a2b9bec0906f0c361e9cf8b9f2 /Zend/tests | |
parent | c94d091889a67472f6da7d56db681ec8cf5be0f3 (diff) | |
download | php-git-dba5a798a28482ce4a6475cc4de1586f11126175.tar.gz |
Fixed #74862: Unable to clone instance when private __clone defined
Even though __clone was implemented as private and called only from
parent class, child extending class instance could not be cloned.
Diffstat (limited to 'Zend/tests')
-rw-r--r-- | Zend/tests/bug74862.phpt | 43 | ||||
-rw-r--r-- | Zend/tests/bug74862_2.phpt | 46 |
2 files changed, 89 insertions, 0 deletions
diff --git a/Zend/tests/bug74862.phpt b/Zend/tests/bug74862.phpt new file mode 100644 index 0000000000..7822575d04 --- /dev/null +++ b/Zend/tests/bug74862.phpt @@ -0,0 +1,43 @@ +--TEST-- +Bug #74862 (Unable to clone instance when private __clone defined) +--FILE-- +<?php + +class a { + private function __clone() + { + + } + + private function __construct() + { + + } + + public static function getInstance() + { + return new static(); + } + + public function cloneIt() + { + $a = clone $this; + + return $a; + } +} + +class c extends a { + +} + +// private constructor +$d = c::getInstance(); + +// private clone +$e = $d->cloneIt(); +var_dump($e); +?> +--EXPECT-- +object(c)#2 (0) { +} diff --git a/Zend/tests/bug74862_2.phpt b/Zend/tests/bug74862_2.phpt new file mode 100644 index 0000000000..2e544a380e --- /dev/null +++ b/Zend/tests/bug74862_2.phpt @@ -0,0 +1,46 @@ +--TEST-- +Bug #74862 (Unable to clone instance when private __clone defined in a child class) +--FILE-- +<?php + +class main { +} + +class a extends main { + private function __clone() + { + + } + + private function __construct() + { + + } + + public static function getInstance() + { + return new static(); + } + + public function cloneIt() + { + $a = clone $this; + + return $a; + } +} + +class c extends a { + +} + +// private constructor +$d = c::getInstance(); + +// private clone +$e = $d->cloneIt(); +var_dump($e); +?> +--EXPECT-- +object(c)#2 (0) { +} |