Skip to content

Commit 0b3f85f

Browse files
committed
Migrate to clone function
1 parent db4e220 commit 0b3f85f

13 files changed

+115
-24
lines changed

Zend/tests/assert/expect_015.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ assert(0 && ($a = function () {
183183
$x = $a ?? $b;
184184
[$a, $b, $c] = [1, 2 => 'x', 'z' => 'c'];
185185
@foo();
186-
$y = clone $x;
186+
$y = \clone($x);
187187
yield 1 => 2;
188188
yield from $x;
189189
}))

Zend/tests/clone/ast.phpt

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,58 @@ try {
3030
echo $e->getMessage(), PHP_EOL;
3131
}
3232

33+
try {
34+
assert(false && $y = clone($x, $array, $extraParameter, $trailingComma, ));
35+
} catch (Error $e) {
36+
echo $e->getMessage(), PHP_EOL;
37+
}
38+
39+
try {
40+
assert(false && $y = clone(object: $x, withProperties: [ "foo" => $foo, "bar" => $bar ]));
41+
} catch (Error $e) {
42+
echo $e->getMessage(), PHP_EOL;
43+
}
44+
45+
try {
46+
assert(false && $y = clone($x, withProperties: [ "foo" => $foo, "bar" => $bar ]));
47+
} catch (Error $e) {
48+
echo $e->getMessage(), PHP_EOL;
49+
}
50+
51+
try {
52+
assert(false && $y = clone(object: $x));
53+
} catch (Error $e) {
54+
echo $e->getMessage(), PHP_EOL;
55+
}
56+
57+
try {
58+
assert(false && $y = clone(object: $x, [ "foo" => $foo, "bar" => $bar ]));
59+
} catch (Error $e) {
60+
echo $e->getMessage(), PHP_EOL;
61+
}
62+
63+
try {
64+
assert(false && $y = clone(...["object" => $x, "withProperties" => [ "foo" => $foo, "bar" => $bar ]]));
65+
} catch (Error $e) {
66+
echo $e->getMessage(), PHP_EOL;
67+
}
68+
69+
try {
70+
assert(false && $y = clone(...));
71+
} catch (Error $e) {
72+
echo $e->getMessage(), PHP_EOL;
73+
}
74+
3375
?>
3476
--EXPECT--
35-
assert(false && ($y = clone($x)))
36-
assert(false && ($y = clone($x)))
37-
assert(false && ($y = clone($x, ['foo' => $foo, 'bar' => $bar])))
38-
assert(false && ($y = clone($x, $array)))
77+
assert(false && ($y = \clone($x)))
78+
assert(false && ($y = \clone($x)))
79+
assert(false && ($y = \clone($x, ['foo' => $foo, 'bar' => $bar])))
80+
assert(false && ($y = \clone($x, $array)))
81+
assert(false && ($y = \clone($x, $array, $extraParameter, $trailingComma)))
82+
assert(false && ($y = \clone(object: $x, withProperties: ['foo' => $foo, 'bar' => $bar])))
83+
assert(false && ($y = \clone($x, withProperties: ['foo' => $foo, 'bar' => $bar])))
84+
assert(false && ($y = \clone(object: $x)))
85+
assert(false && ($y = \clone(object: $x, ['foo' => $foo, 'bar' => $bar])))
86+
assert(false && ($y = \clone(...['object' => $x, 'withProperties' => ['foo' => $foo, 'bar' => $bar]])))
87+
assert(false && ($y = \clone(...)))

Zend/tests/clone/bug36071.phpt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ $a = clone 0;
88
$a[0]->b = 0;
99
?>
1010
--EXPECTF--
11-
Fatal error: Uncaught Error: __clone method called on non-object in %sbug36071.php:2
11+
Fatal error: Uncaught TypeError: clone(): Argument #1 ($object) must be of type object, int given in %s:%d
1212
Stack trace:
13-
#0 {main}
13+
#0 %s(%d): clone(0)
14+
#1 {main}
1415
thrown in %sbug36071.php on line 2

Zend/tests/clone/bug42817.phpt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ $a = clone(null);
66
array_push($a->b, $c);
77
?>
88
--EXPECTF--
9-
Fatal error: Uncaught Error: __clone method called on non-object in %sbug42817.php:2
9+
Fatal error: Uncaught TypeError: clone(): Argument #1 ($object) must be of type object, null given in %s:%d
1010
Stack trace:
11-
#0 {main}
11+
#0 %s(%d): clone(NULL)
12+
#1 {main}
1213
thrown in %sbug42817.php on line 2

Zend/tests/clone/bug42818.phpt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Bug #42818 ($foo = clone(array()); leaks memory)
55
$foo = clone(array());
66
?>
77
--EXPECTF--
8-
Fatal error: Uncaught Error: __clone method called on non-object in %sbug42818.php:2
8+
Fatal error: Uncaught TypeError: clone(): Argument #1 ($object) must be of type object, array given in %s:%d
99
Stack trace:
10-
#0 {main}
10+
#0 %s(%d): clone(Array)
11+
#1 {main}
1112
thrown in %sbug42818.php on line 2

Zend/tests/clone/callback.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
As Callback
3+
--FILE--
4+
<?php
5+
6+
class Foo {
7+
private function __clone() {
8+
9+
}
10+
11+
public function clone_me() {
12+
return array_map(clone(...), [$this]);
13+
}
14+
}
15+
16+
$f = new Foo();
17+
18+
$clone = $f->clone_me()[0];
19+
20+
var_dump($f !== $clone);
21+
22+
?>
23+
--EXPECT--
24+
bool(true)

Zend/tests/clone/clone_001.phpt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ $a = clone array();
77

88
?>
99
--EXPECTF--
10-
Fatal error: Uncaught Error: __clone method called on non-object in %s:%d
10+
Fatal error: Uncaught TypeError: clone(): Argument #1 ($object) must be of type object, array given in %s:%d
1111
Stack trace:
12-
#0 {main}
12+
#0 %s(%d): clone(Array)
13+
#1 {main}
1314
thrown in %s on line %d

Zend/tests/clone/clone_003.phpt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ $a = clone $b;
99
--EXPECTF--
1010
Warning: Undefined variable $b in %s on line %d
1111

12-
Fatal error: Uncaught Error: __clone method called on non-object in %s:%d
12+
Fatal error: Uncaught TypeError: clone(): Argument #1 ($object) must be of type object, null given in %s:%d
1313
Stack trace:
14-
#0 {main}
14+
#0 %s(%d): clone(NULL)
15+
#1 {main}
1516
thrown in %s on line %d

Zend/tests/clone/clone_with_001.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ $array = [
1414
'array' => [1, 2, 3],
1515
];
1616

17+
function gen() {
18+
yield 'from_gen' => 'value';
19+
}
20+
1721
var_dump(clone $x);
1822
var_dump(clone($x));
1923
var_dump(clone($x, [ 'foo' => $foo, 'bar' => $bar ]));

Zend/tests/clone/clone_with_006.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ try {
1313

1414
?>
1515
--EXPECT--
16-
TypeError: Updated properties must be of type array, int given
16+
TypeError: clone(): Argument #2 ($withProperties) must be of type array, int given

0 commit comments

Comments
 (0)