Skip to content

Commit 6cec238

Browse files
committed
Migrate to clone function
1 parent 7def4a7 commit 6cec238

12 files changed

+71
-23
lines changed

Zend/tests/assert/expect_015.phpt

+1-1
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

+5-5
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ try {
4242

4343
?>
4444
--EXPECT--
45-
assert(false && ($y = clone($x)))
46-
assert(false && ($y = clone($x)))
47-
assert(false && ($y = clone($x, foo: $foo, bar: $bar)))
48-
assert(false && ($y = clone($x, ...$array)))
49-
assert(false && ($y = clone($x, ...['foo' => $foo, 'bar' => $bar])))
45+
assert(false && ($y = \clone($x)))
46+
assert(false && ($y = \clone($x)))
47+
assert(false && ($y = \clone($x, foo: $foo, bar: $bar)))
48+
assert(false && ($y = \clone($x, ...$array)))
49+
assert(false && ($y = \clone($x, ...['foo' => $foo, 'bar' => $bar])))

Zend/tests/clone/bug36071.phpt

+3-2
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

+3-2
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

+3-2
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

+24
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

+3-2
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

+3-2
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

+10
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));
@@ -27,6 +31,8 @@ var_dump(clone($x, ...[
2731
'named' => 'value',
2832
]));
2933

34+
var_dump(clone($x, ...gen()));
35+
3036
?>
3137
--EXPECTF--
3238
object(stdClass)#%d (0) {
@@ -69,3 +75,7 @@ object(stdClass)#%d (4) {
6975
["named"]=>
7076
string(5) "value"
7177
}
78+
object(stdClass)#%d (1) {
79+
["from_gen"]=>
80+
string(5) "value"
81+
}

Zend/tests/clone/clone_with_006.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ try {
1313

1414
?>
1515
--EXPECT--
16-
TypeError: Only arrays can be unpacked for clone, int given
16+
TypeError: Only arrays and Traversables can be unpacked, int given

Zend/tests/magic_methods/bug73288.phpt

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ test_clone();
2828
--EXPECTF--
2929
Fatal error: Uncaught Exception: No Cloneable in %sbug73288.php:%d
3030
Stack trace:
31-
#0 %s(%d): NoClone->__clone()
32-
#1 %s(%d): test_clone()
33-
#2 {main}
31+
#0 [internal function]: NoClone->__clone()
32+
#1 %s(%d): clone(Object(NoClone))
33+
#2 %s(%d): test_clone()
34+
#3 {main}
3435
thrown in %sbug73288.php on line %d

Zend/zend_language_parser.y

+11-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
4646
%define api.pure full
4747
%define api.value.type {zend_parser_stack_elem}
4848
%define parse.error verbose
49-
%expect 0
49+
%expect 1
5050

5151
%destructor { zend_ast_destroy($$); } <ast>
5252
%destructor { if ($$) zend_string_release_ex($$, 0); } <str>
@@ -1214,8 +1214,16 @@ expr:
12141214
{ $$ = zend_ast_create(ZEND_AST_ASSIGN, $1, $3); }
12151215
| variable '=' ampersand variable
12161216
{ $$ = zend_ast_create(ZEND_AST_ASSIGN_REF, $1, $4); }
1217-
| T_CLONE '(' expr ',' non_empty_argument_list ')' { $$ = zend_ast_create(ZEND_AST_CLONE, $3, $5); }
1218-
| T_CLONE expr { $$ = zend_ast_create(ZEND_AST_CLONE, $2, NULL); }
1217+
| T_CLONE argument_list {
1218+
zend_ast *name = zend_ast_create_zval_from_str(ZSTR_KNOWN(ZEND_STR_CLONE));
1219+
name->attr = ZEND_NAME_FQ;
1220+
$$ = zend_ast_create(ZEND_AST_CALL, name, $2);
1221+
}
1222+
| T_CLONE expr {
1223+
zend_ast *name = zend_ast_create_zval_from_str(ZSTR_KNOWN(ZEND_STR_CLONE));
1224+
name->attr = ZEND_NAME_FQ;
1225+
$$ = zend_ast_create(ZEND_AST_CALL, name, zend_ast_create_list(1, ZEND_AST_ARG_LIST, $2));
1226+
}
12191227
| variable T_PLUS_EQUAL expr
12201228
{ $$ = zend_ast_create_assign_op(ZEND_ADD, $1, $3); }
12211229
| variable T_MINUS_EQUAL expr

0 commit comments

Comments
 (0)