Created
March 29, 2015 00:29
-
-
Save amcsi/b56aa402e088a40bf8e9 to your computer and use it in GitHub Desktop.
Access protected methods and properties easily without reflection with the new anonymous classes feature
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 A { | |
protected $protectedProperty = 'default'; | |
public function get() | |
{ | |
return $this->protectedProperty; | |
} | |
} | |
$a = new A; | |
$a->get(); // 'default'; | |
(new class ($a) extends A { | |
public function __construct(A $a) | |
{ | |
$a->protectedProperty = 'overridden'; | |
} | |
}) | |
$a->get(); // 'overridden' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment