Last active
January 31, 2018 09:51
-
-
Save bagart/2bab7c4db81a51d0a6c361de3d3f89c0 to your computer and use it in GitHub Desktop.
private access in PHP / encapsulation hack
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 | |
declare(strict_types=1); | |
final class A { | |
private $prop; | |
public function __construct(DateTime $prop) { $this->prop = $prop; } | |
public function getProp() { return $this->prop; } | |
} | |
$a = new A(new DateTime()); | |
var_dump($a->getProp()); | |
(function (){ | |
return $this->prop = "injection success"; | |
})->call($a); | |
var_dump($a->getProp()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
RESULT