Guest User

Untitled

a guest
Jul 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. <?php
  2. //function to load and rename Class1 to Class2: does something like this exist?
  3. load_and_rename_class('Class1', 'Class2');
  4.  
  5. //now i can extend the renamed class and use the original name:
  6. class Class1 extends Class2{
  7. }
  8. ?>
  9.  
  10. // A class you can't change
  11. class ImmutableClass {
  12. private function __construct() {
  13. $this->myObject = new AnotherImmutableClass();
  14. }
  15. }
  16.  
  17. $immutable = new ImmutableClass();
  18.  
  19. // And now you want to call a custom, currently non existing method on myObject
  20. // Because for some reason you need the context that this instance provides
  21. $immutable->myObject->yourCustomMethod();
  22.  
  23. // Helper function
  24. doSomethingToMyObject($immutable->myObject);
  25. // Or decorator method
  26. $myDecoratedObject = new objectDecorator($immutable->myObject);
  27. $myDecoratedObject->doSomethingToMyObject();
Add Comment
Please, Sign In to add comment