Advertisement
sri211500

Untitled

Feb 25th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. <?php
  2. class Test
  3. {
  4. private $foo;
  5.  
  6. public function __construct($foo)
  7. {
  8. $this->foo = $foo;
  9. }
  10. private function bar()
  11. {
  12. echo 'Accessed the private method.';
  13. }
  14. public function bez(Test $other)
  15. {
  16. // We can change the private property:
  17. $other->foo = 'hello';
  18. var_dump($other->foo);
  19.  
  20. // We can also call the private method:
  21. $other->bar();
  22. }
  23. }
  24.  
  25. $test = new Test('test');
  26.  
  27. $test->baz(new Test('orter'));
  28. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement