Advertisement
p5ych0pat

Untitled

Oct 27th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.49 KB | None | 0 0
  1. <?php
  2. class PropertyContainer
  3. {
  4.  
  5.     public $somePublicArray = [0];
  6.  
  7.     public function __construct($data = [])
  8.     {
  9.         $that = $this;
  10.  
  11.         array_walk($data, function ($item, $key) use ($that) {
  12.             $that->{$key} = $item;
  13.         });
  14.     }
  15.  
  16. }
  17.  
  18. $cont = new PropertyContainer(['a' => 1, 'b' => [0], 'c' => new ArrayObject ([0])]);
  19.  
  20. $cont->a++;
  21. $cont->b[] = 1;
  22. $cont->somePublicArray[] = 1;
  23. $cont->c[] = 1;
  24.  
  25. var_dump($cont, is_array($cont->c), is_array($cont->b));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement