Skip to content

Instantly share code, notes, and snippets.

@luciansabo
Created April 5, 2018 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luciansabo/b7c8abac41bed52bfb37ef82084c8f5b to your computer and use it in GitHub Desktop.
Save luciansabo/b7c8abac41bed52bfb37ef82084c8f5b to your computer and use it in GitHub Desktop.
<?php
class CoolDto
{
public $master = 'admin';
public $child;
public function __construct()
{
$this->child = $this->createChildDto();
}
protected function createChildDto()
{
return new class() {
public $x1 = 1;
public $x2 = 2;
};
}
}
$x = new CoolDto();
$x->child->x1 += 80;
echo json_encode($x);
// output: {"master":"admin","child":{"x1":81,"x2":2}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment