Rofihimam

Untitled

Feb 12th, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.46 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.  
  11.         private function bar()
  12.         {
  13.             echo 'Accessed the private method.';
  14.         }
  15.  
  16.         public function baz(Test $other)
  17.         {
  18.             // we can change the private property:
  19.             $other->foo = 'hello';
  20.             var_dump($other->foo);
  21.  
  22.             // we can also call the privet method:
  23.             $other->bar();
  24.         }
  25.     }
  26.  
  27.     $test = new Test('test');
  28.     $test->baz(new Test('other'));
  29. ?>
Advertisement
Add Comment
Please, Sign In to add comment