Created
November 10, 2016 21:42
-
-
Save skrajewski/5b8065c67f216647be4a6e9ad8181c82 to your computer and use it in GitHub Desktop.
Create instance of me!
This file contains hidden or 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 Dog { | |
private $dog; | |
public function __construct(Dog $dog) | |
{ | |
$this->dog = $dog; | |
} | |
public function getDog() | |
{ | |
return $this->dog; | |
} | |
} | |
$reflection = new ReflectionClass(Dog::class); | |
$dog = $reflection->newInstanceWithoutConstructor(); | |
$property = $reflection->getProperty('dog'); | |
$property->setAccessible(true); | |
$property->setValue($dog, $dog); | |
var_dump($dog); | |
var_dump($dog->getDog()); | |
var_dump($dog === $dog); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment