Skip to content

Commit 2f31b13

Browse files
committed
Update the syntax of clone with
1 parent ac04bf5 commit 2f31b13

30 files changed

+75
-76
lines changed

Zend/tests/clone_initializer/clone_initializer_error1.phpt

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

1414
?>
1515
--EXPECTF--
16-
Parse error: syntax error, unexpected token ";", expecting "{" in %s on line %d
16+
Parse error: syntax error, unexpected token ";", expecting "[" in %s on line %d

Zend/tests/clone_initializer/clone_initializer_error10.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ class Foo
1515
$foo1 = new Foo(0);
1616

1717
try {
18-
$foo2 = clone $foo1 with {bar: 1};
18+
$foo2 = clone $foo1 with ["bar" => 1];
1919
} catch (Error $exception) {
2020
echo $exception->getMessage() . "\n";
2121
}
2222

2323
try {
24-
$foo2 = clone $foo1 with {baz: 1};
24+
$foo2 = clone $foo1 with ["baz" => 1];
2525
} catch (Error $exception) {
2626
echo $exception->getMessage() . "\n";
2727
}

Zend/tests/clone_initializer/clone_initializer_error11.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ class Foo
1616

1717
public function with()
1818
{
19-
return clone $this with {
19+
return clone $this with [
2020
"bar" => 1,
2121
"bar" => 2,
22-
};
22+
];
2323
}
2424
}
2525

Zend/tests/clone_initializer/clone_initializer_error2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Foo
77
{
88
public function withProperties()
99
{
10-
return clone $this with {1: "value"};
10+
return clone $this with [1: "value"];
1111
}
1212
}
1313

Zend/tests/clone_initializer/clone_initializer_error3.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Foo
1111
$foo = new Foo();
1212

1313
try {
14-
$foo = clone $foo with {bar: 1};
14+
$foo = clone $foo with ["bar" => 1];
1515
} catch (Error $exception) {
1616
echo $exception->getMessage() . "\n";
1717
}

Zend/tests/clone_initializer/clone_initializer_error4.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ class Foo
1111

1212
public function with()
1313
{
14-
return clone $this with {
15-
bar: 1,
16-
bar: 2,
17-
};
14+
return clone $this with [
15+
"bar" => 1,
16+
"bar" => 2,
17+
];
1818
}
1919
}
2020

Zend/tests/clone_initializer/clone_initializer_error5.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ class Foo
1111
$obj1 = new Foo();
1212

1313
try {
14-
clone $obj1 with {bar: []};
14+
clone $obj1 with ["bar" => []];
1515
} catch (TypeError $e) {
1616
echo $e->getMessage() . "\n";
1717
}
1818

1919
try {
20-
clone $obj1 with {bar: []}; // The same as above but now using cache slots
20+
clone $obj1 with ["bar" => []]; // The same as above but now using cache slots
2121
} catch (TypeError $e) {
2222
echo $e->getMessage() . "\n";
2323
}

Zend/tests/clone_initializer/clone_initializer_error6.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ function returnFoo() {
1717
}
1818

1919
try {
20-
clone returnFoo() with {bar: new stdClass()};
20+
clone returnFoo() with ["bar" => new stdClass()];
2121
} catch (Exception $e) {
2222
echo $e->getMessage() . "\n";
2323
}
2424

2525
try {
26-
clone returnFoo() with {bar: new stdClass()}; // The same as above but now using cache slots
26+
clone returnFoo() with ["bar" => new stdClass()]; // The same as above but now using cache slots
2727
} catch (Exception $e) {
2828
echo $e->getMessage() . "\n";
2929
}

Zend/tests/clone_initializer/clone_initializer_error7.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ function returnFoo() {
1616
}
1717

1818
try {
19-
clone returnFoo() with {bar: new stdClass()};
19+
clone returnFoo() with ["bar" => new stdClass()];
2020
} catch (Exception $e) {
2121
echo $e->getMessage() . "\n";
2222
}
2323

2424
try {
25-
clone returnFoo() with {bar: new stdClass()}; // The same as above but now using cache slots
25+
clone returnFoo() with ["bar" => new stdClass()]; // The same as above but now using cache slots
2626
} catch (Exception $e) {
2727
echo $e->getMessage() . "\n";
2828
}

Zend/tests/clone_initializer/clone_initializer_error8.phpt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,49 @@ Test "clone with" with invalid property names
44
<?php
55

66
try {
7-
clone new stdClass() with {$undefined => 1};
7+
clone new stdClass() with [$undefined => 1];
88
} catch (TypeError $e) {
99
echo $e->getMessage() . "\n";
1010
}
1111

1212
try {
13-
clone new stdClass() with {$undefined => 1}; // The same as above but now using cache slots
13+
clone new stdClass() with [$undefined => 1]; // The same as above but now using cache slots
1414
} catch (TypeError $e) {
1515
echo $e->getMessage() . "\n";
1616
}
1717

1818
try {
19-
clone new stdClass() with {null => 1};
19+
clone new stdClass() with [null => 1];
2020
} catch (TypeError $e) {
2121
echo $e->getMessage() . "\n";
2222
}
2323

2424
try {
25-
clone new stdClass() with {null => 1}; // The same as above but now using cache slots
25+
clone new stdClass() with [null => 1]; // The same as above but now using cache slots
2626
} catch (TypeError $e) {
2727
echo $e->getMessage() . "\n";
2828
}
2929

3030
try {
31-
clone new stdClass() with {[] => 1};
31+
clone new stdClass() with [[] => 1];
3232
} catch (TypeError $e) {
3333
echo $e->getMessage() . "\n";
3434
}
3535

3636
try {
37-
clone new stdClass() with {[] => 1}; // The same as above but now using cache slots
37+
clone new stdClass() with [[] => 1]; // The same as above but now using cache slots
3838
} catch (TypeError $e) {
3939
echo $e->getMessage() . "\n";
4040
}
4141

4242
try {
43-
clone new stdClass() with {1 => 1};
43+
clone new stdClass() with [1 => 1];
4444
} catch (TypeError $e) {
4545
echo $e->getMessage() . "\n";
4646
}
4747

4848
try {
49-
clone new stdClass() with {1 => 1}; // The same as above but now using cache slots
49+
clone new stdClass() with [1 => 1]; // The same as above but now using cache slots
5050
} catch (TypeError $e) {
5151
echo $e->getMessage() . "\n";
5252
}

Zend/tests/clone_initializer/clone_initializer_error9.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ class Foo
1111

1212
public function with()
1313
{
14-
return clone $this with {
15-
bar: 1,
16-
};
14+
return clone $this with [
15+
"bar" => 1,
16+
];
1717
}
1818

1919
public function assign()

Zend/tests/clone_initializer/clone_initializer_success1.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ class Foo
1010

1111
public function withProperties($property1, $property2)
1212
{
13-
return clone $this with {
14-
property1: $property1,
15-
property2: $property2,
16-
};
13+
return clone $this with [
14+
"property1" => $property1,
15+
"property2" => $property2,
16+
];
1717
}
1818
}
1919

Zend/tests/clone_initializer/clone_initializer_success10.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ try {
1414
}
1515

1616
try {
17-
assert(clone new stdClass() with {} === null);
17+
assert(clone new stdClass() with [] === null);
1818
} catch (AssertionError $e) {
1919
echo $e->getMessage() . "\n";
2020
}
2121

2222
try {
23-
assert(clone new stdClass() with {foo: 1, bar: "abc"} === null);
23+
assert(clone new stdClass() with ["foo" => 1, "bar" => "abc"] === null);
2424
} catch (AssertionError $e) {
2525
echo $e->getMessage() . "\n";
2626
}
2727

2828
?>
2929
--EXPECT--
3030
assert(clone new stdClass() === null)
31-
assert(clone new stdClass() with {} === null)
32-
assert(clone new stdClass() with {foo: 1, bar: 'abc'} === null)
31+
assert(clone new stdClass() with [] === null)
32+
assert(clone new stdClass() with ['foo' => 1, 'bar' => 'abc'] === null)

Zend/tests/clone_initializer/clone_initializer_success11.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,26 @@ class Foo
1111
{
1212
$property = "property1";
1313

14-
return clone $this with {$property => "value"};
14+
return clone $this with [$property => "value"];
1515
}
1616

1717
public function withProperty2()
1818
{
1919
$property = "string";
2020

21-
return clone $this with {$this->getProperty1Name() => "value"};
21+
return clone $this with [$this->getProperty1Name() => "value"];
2222
}
2323

2424
public function withProperty3()
2525
{
2626
$property = "property2";
2727

28-
return clone $this with {$property => "value"};
28+
return clone $this with [$property => "value"];
2929
}
3030

3131
public function withProperty4()
3232
{
33-
return clone $this with {substr($this->getProperty1Name(), 0, 8) . "1" => "value"};
33+
return clone $this with [substr($this->getProperty1Name(), 0, 8) . "1" => "value"];
3434
}
3535

3636
private function getProperty1Name() {

Zend/tests/clone_initializer/clone_initializer_success12.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ class Foo
1111

1212
public function with()
1313
{
14-
return clone $this with {
15-
bar: 1,
16-
bar: 2,
17-
bar: 3,
18-
};
14+
return clone $this with [
15+
"bar" => 1,
16+
"bar" => 2,
17+
"bar" => 3,
18+
];
1919
}
2020
}
2121

Zend/tests/clone_initializer/clone_initializer_success13.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ class Foo
1111

1212
public function with()
1313
{
14-
return clone $this with {
14+
return clone $this with [
1515
"bar" => 1,
16-
};
16+
];
1717
}
1818
}
1919

Zend/tests/clone_initializer/clone_initializer_success14.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class Foo
1616

1717
public function with()
1818
{
19-
return clone $this with {
19+
return clone $this with [
2020
"bar" => 2,
21-
};
21+
];
2222
}
2323
}
2424

Zend/tests/clone_initializer/clone_initializer_success2.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ class Foo
77
{
88
public function withProperties($property1, $property2)
99
{
10-
return clone $this with {
11-
property1: $property1,
12-
property2: $property2,
13-
};
10+
return clone $this with [
11+
"property1" => $property1,
12+
"property2" => $property2,
13+
];
1414
}
1515
}
1616

Zend/tests/clone_initializer/clone_initializer_success3.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Foo
77
{
88
public function withProperties()
99
{
10-
return clone $this with {};
10+
return clone $this with [];
1111
}
1212
}
1313

Zend/tests/clone_initializer/clone_initializer_success4.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Foo
99

1010
public function withProperties()
1111
{
12-
return (clone $this with {})->bar;
12+
return (clone $this with [])->bar;
1313
}
1414
}
1515

Zend/tests/clone_initializer/clone_initializer_success5.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Test that the "clone with" respects #[AllowDynamicProperties]
44
<?php
55

66
$obj1 = new stdClass();
7-
$obj2 = clone $obj1 with {foo: 1, bar: ""};
8-
$obj3 = clone $obj1 with {foo: 2, bar: []};
7+
$obj2 = clone $obj1 with ["foo" => 1, "bar" => ""];
8+
$obj3 = clone $obj1 with ["foo" => 2, "bar" => []];
99

1010
var_dump($obj1);
1111
var_dump($obj2);

Zend/tests/clone_initializer/clone_initializer_success6.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class Foo
1010
}
1111

1212
$obj1 = new Foo();
13-
$obj2 = clone $obj1 with {bar: new stdClass(), baz: strpos("abc", "b")};
14-
$obj3 = clone $obj2 with {bar: new stdClass(), baz: ["abc", "def"]}; // The same as above but now using cache slots
13+
$obj2 = clone $obj1 with ["bar" => new stdClass(), "baz" => strpos("abc", "b")];
14+
$obj3 = clone $obj2 with ["bar" => new stdClass(), "baz" => ["abc", "def"]]; // The same as above but now using cache slots
1515

1616
var_dump($obj1);
1717
var_dump($obj2);

Zend/tests/clone_initializer/clone_initializer_success7.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Foo
1111
}
1212
}
1313

14-
$foo = clone Foo::create() with {};
14+
$foo = clone Foo::create() with [];
1515
var_dump($foo);
1616

1717
?>

Zend/tests/clone_initializer/clone_initializer_success8.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Foo
1212
$foo = new Foo();
1313
$ref = &$foo;
1414

15-
$bar = clone $ref with {property1: 1, property2: 2};
15+
$bar = clone $ref with ["property1" => 1, "property2" => 2];
1616
var_dump($bar);
1717

1818
?>

Zend/tests/clone_initializer/clone_initializer_success9.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ class Foo
1212

1313
public function with(int $bar, stdClass $baz)
1414
{
15-
return clone $this with {
16-
bar: $bar,
17-
baz: $baz,
18-
};
15+
return clone $this with [
16+
"bar" => $bar,
17+
"baz" => $baz,
18+
];
1919
}
2020
}
2121

0 commit comments

Comments
 (0)