-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
5 changed files
with
106 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) { | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) { | ||
} |
This file contains 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
This file contains 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