Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //function to load and rename Class1 to Class2: does something like this exist?
- load_and_rename_class('Class1', 'Class2');
- //now i can extend the renamed class and use the original name:
- class Class1 extends Class2{
- }
- ?>
- // A class you can't change
- class ImmutableClass {
- private function __construct() {
- $this->myObject = new AnotherImmutableClass();
- }
- }
- $immutable = new ImmutableClass();
- // And now you want to call a custom, currently non existing method on myObject
- // Because for some reason you need the context that this instance provides
- $immutable->myObject->yourCustomMethod();
- // Helper function
- doSomethingToMyObject($immutable->myObject);
- // Or decorator method
- $myDecoratedObject = new objectDecorator($immutable->myObject);
- $myDecoratedObject->doSomethingToMyObject();
Add Comment
Please, Sign In to add comment