@@ -9,20 +9,14 @@ protected function emitClone($result, $clone) {
9
9
$ expr = $ clone ->arguments ['object ' ] ?? $ clone ->arguments [0 ] ?? null ;
10
10
$ with = $ clone ->arguments ['withProperties ' ] ?? $ clone ->arguments [1 ] ?? null ;
11
11
12
- // Wrap clone with, e.g. clone($x, ['id' => 6100]), inside an IIFE as follows:
13
- // `function($args) { $this->id= $args['id']; return $this; }`, then bind
14
- // this closure to the cloned instance before invoking it with the named
15
- // arguments so we can access non-public members.
12
+ // Wrap clone with, e.g. clone($x, ['id' => 6100]), inside an IIFE which
13
+ /// iterates over the property-value pairs, assigning them to the clone.
16
14
if ($ with ) {
17
- $ c = $ result ->temp ();
18
- $ a = $ result ->temp ();
19
-
20
- $ result ->out ->write ('[ ' .$ c .'=clone ' );
15
+ $ result ->out ->write ('(function($c, $a) { foreach ($a as $p=>$v) { $c->$p= $v; } return $c;})(clone ' );
21
16
$ this ->emitOne ($ result , $ expr );
22
- $ result ->out ->write (', ' . $ a . ' = ' );
17
+ $ result ->out ->write (', ' );
23
18
$ this ->emitOne ($ result , $ with );
24
- $ result ->out ->write (']?(function($a) { foreach ($a as $p=>$v) { $this->$p= $v; }return $this;}) ' );
25
- $ result ->out ->write ('->bindTo( ' .$ c .', ' .$ c .')( ' .$ a .'):null ' );
19
+ $ result ->out ->write (') ' );
26
20
} else if (isset ($ clone ->arguments ['object ' ])) {
27
21
$ result ->out ->write ('clone ' );
28
22
$ this ->emitOne ($ result , $ expr );
0 commit comments