Skip to content

Instantly share code, notes, and snippets.

@amcsi
Created March 29, 2015 00:29
Show Gist options
  • Save amcsi/b56aa402e088a40bf8e9 to your computer and use it in GitHub Desktop.
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
<?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