Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #8569 #8570

Merged
merged 2 commits into from Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -557,7 +557,11 @@ public function start(PhpParser\Node\FunctionLike $stmt, bool $fake_method = fal
= $classlike_storage->appearing_method_ids[$method_name_lc]
= $method_id;

if (!$stmt->isPrivate() || $method_name_lc === '__construct' || $classlike_storage->is_trait) {
if (!$stmt->isPrivate()
|| $method_name_lc === '__construct'
|| $method_name_lc === '__clone'
|| $classlike_storage->is_trait
) {
$classlike_storage->inheritable_method_ids[$method_name_lc] = $method_id;
}

Expand Down
22 changes: 22 additions & 0 deletions tests/CloneTest.php
Expand Up @@ -82,6 +82,28 @@ private function __clone() {}
clone $a;',
'error_message' => 'InvalidClone',
],
'notVisibleCloneMethodSubClass' => [
'code' => '<?php
class a {
private function __clone() {}
}
class b extends a {}

clone new b;',
'error_message' => 'InvalidClone',
],
'notVisibleCloneMethodTrait' => [
'code' => '<?php
trait a {
private function __clone() {}
}
class b {
use a;
}

clone new b;',
'error_message' => 'InvalidClone',
],
'invalidGenericClone' => [
'code' => '<?php
/**
Expand Down