Advertisement
imoda

PHP Class, set and get

Sep 23rd, 2011
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1. <?php
  2.  
  3. class myClass{
  4.     function __set($arg_1, $arg_2){
  5.          echo "__set($arg_1, $arg_2)".PHP_EOL;
  6.             if(is_array($arg_2)){
  7.                echo "Setting array $arg_1 to $arg_2".PHP_EOL;
  8.             }
  9.             else {
  10.                echo "setting string $arg_1 to $arg_2".PHP_EOL;
  11.             }
  12.             $this->$arg_1 = $arg_2;
  13.     }
  14.  
  15.     function __get($arg){
  16.          echo "showing $arg".PHP_EOL;
  17.          return 'ERROR! variable does not exist';
  18.     }
  19. }
  20.  
  21.  
  22. $mClass = new myClass();
  23.  
  24. $mClass->hello = 'this and that';
  25.  
  26. echo "Hi there: ". $mClass->hello.PHP_EOL;
  27.  
  28.  
  29. $mClass->hello_again = array('this and that');
  30.  
  31. echo "Hi again: ".$mClass->hello_again.PHP_EOL;
  32.  
  33. echo $mClass->hello_again_2;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement