Skip to content

Instantly share code, notes, and snippets.

@iluuu1994
Last active March 20, 2024 18:24
Show Gist options
  • Save iluuu1994/cc62341ebab8018e8d69f30dd17a6dda to your computer and use it in GitHub Desktop.
Save iluuu1994/cc62341ebab8018e8d69f30dd17a6dda to your computer and use it in GitHub Desktop.
<?php
data class Vec {
public function __construct(
public $x,
public $y,
) {}
public mutating function double() {
$this->x *= 2;
$this->y *= 2;
}
public function print() {
echo "Vec({$this->x}, {$this->y})\n";
}
}
$vec = new Vec(1, 2);
$vec2 = $vec; // References the same object
$vec2->double(); // Needs to cause separation of $vec/$vec2.
data class Rect {
public function __construct(
public Vec $pos,
) {}
}
$rect = new Rect($vec);
$rect->pos->double();
// Needs to separate both $rect and pos. However, by the time we know we need to
// separate (on INIT_METHOD_CALL), we're already passed the FETCH_OBJ_R.
// Repeating the opcodes is not possible if the input to the fetch is a
// [TMP]VAR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment