mirror of
https://github.com/php/php-src.git
synced 2026-03-24 16:22:37 +01:00
This is in preparation for the possible future transformation of `clone` into a function call, but also meaningful on its own, since the purpose of the tests is not to test the stack trace generation, but rather that an exception was thrown. It also cleans up some unreachable code in the tests.
76 lines
1.6 KiB
PHP
76 lines
1.6 KiB
PHP
--TEST--
|
|
Testing ReflectionClass::isCloneable()
|
|
--EXTENSIONS--
|
|
simplexml
|
|
xmlwriter
|
|
--FILE--
|
|
<?php
|
|
|
|
class foo {
|
|
}
|
|
$foo = new foo;
|
|
|
|
print "User class\n";
|
|
$obj = new ReflectionClass($foo);
|
|
var_dump($obj->isCloneable());
|
|
$obj = new ReflectionObject($foo);
|
|
var_dump($obj->isCloneable());
|
|
$h = clone $foo;
|
|
|
|
class bar {
|
|
private function __clone() {
|
|
}
|
|
}
|
|
$bar = new bar;
|
|
print "User class - private __clone\n";
|
|
$obj = new ReflectionClass($bar);
|
|
var_dump($obj->isCloneable());
|
|
$obj = new ReflectionObject($bar);
|
|
var_dump($obj->isCloneable());
|
|
$h = clone $foo;
|
|
|
|
print "Closure\n";
|
|
$closure = function () { };
|
|
$obj = new ReflectionClass($closure);
|
|
var_dump($obj->isCloneable());
|
|
$obj = new ReflectionObject($closure);
|
|
var_dump($obj->isCloneable());
|
|
$h = clone $closure;
|
|
|
|
print "Internal class - SimpleXMLElement\n";
|
|
$obj = new ReflectionClass('simplexmlelement');
|
|
var_dump($obj->isCloneable());
|
|
$obj = new ReflectionObject(new simplexmlelement('<test></test>'));
|
|
var_dump($obj->isCloneable());
|
|
$h = clone new simplexmlelement('<test></test>');
|
|
|
|
print "Internal class - XMLWriter\n";
|
|
$obj = new ReflectionClass('xmlwriter');
|
|
var_dump($obj->isCloneable());
|
|
$obj = new ReflectionObject(new XMLWriter);
|
|
var_dump($obj->isCloneable());
|
|
try {
|
|
$h = clone new xmlwriter;
|
|
} catch (Throwable $e) {
|
|
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
|
|
}
|
|
|
|
?>
|
|
--EXPECT--
|
|
User class
|
|
bool(true)
|
|
bool(true)
|
|
User class - private __clone
|
|
bool(false)
|
|
bool(false)
|
|
Closure
|
|
bool(true)
|
|
bool(true)
|
|
Internal class - SimpleXMLElement
|
|
bool(true)
|
|
bool(true)
|
|
Internal class - XMLWriter
|
|
bool(false)
|
|
bool(false)
|
|
Error: Trying to clone an uncloneable object of class XMLWriter
|