Created
April 5, 2018 15:37
-
-
Save luciansabo/b7c8abac41bed52bfb37ef82084c8f5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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