<?php
class Foo {
private final function __clone() {
var_dump(__METHOD__);
}
}
class Bar extends Foo {
}
$x = new Bar();
$_ = clone $x;
PHP: runtime error: Call to private Foo::__clone()
KPHP: no errors, default (?) cloning is performed
The final private __clone is a trick to make objects non-cloneable.
Note: even if we make the __clone() public (final is irrelevant), it's not going to be called from the derived objects.
<?php
class Foo {
public function __clone() {
var_dump(__METHOD__);
}
}
class Bar extends Foo {}
class Baz extends Bar {}
$x = new Baz();
$_ = clone $x;
PHP: prints "Foo::__clone"
KPHP: prints nothing
PHP: runtime error: Call to private Foo::__clone()
KPHP: no errors, default (?) cloning is performed
The
final private __cloneis a trick to make objects non-cloneable.Note: even if we make the
__clone()public (final is irrelevant), it's not going to be called from the derived objects.PHP: prints
"Foo::__clone"KPHP: prints nothing