<?php class Context { private int $a; private int $b; /** * @param int $a */ public function setA(int $a): self { $new = new self(); $new->setA($a); $new->setB($this->b); return $new; } public function setB(int $b): self { $new = new self(); $new->setA($this->a); $new->setB($b); return $new; } public function getData(): array { return [ 'a' => $this->a, 'b' => $this->b, ]; } } function test(Context &$context) { $context = $context->setB(5); } $context = new Context(); $context = $context->setA(2); test($context); var_dump($context->getData());
You have javascript disabled. You will not be able to edit any code.