[ create a new paste ] login | about

Link: http://codepad.org/naep51ON    [ raw code | output | fork ]

php.programmer - PHP, pasted on Apr 14:
<?php
/* sample code of implementation of Member overloading with help of magic functions
 * __set(), __get(), __isset(), __unset()
 * author : http://royads.blogspot.com
*/
class test
{
  protected $defiened;
  protected $data = array();
  public function __set($name,$value)
  {
    echo "\nset data in array"; 
    $this->data[$name] = $value;
  }
  public function __get($name)
  {
    echo "\nget from array";
    if(array_key_exists($name,$this->data))
      return $this->data[$name];
    else
      return NULL;
  }
  public function __isset($name)
  {
       echo "\nchking if set";
       return isset($this->data[$name]);
  }
  public function __unset($name)
  {
       echo "\nunseting";
       unset($this->data[$name]);
  }
}
$obj    = new test();
echo $obj->notdefiened;
$obj->notdefiened = 'r u there??';
echo $obj->notdefiened;

if(isset($obj->notdefiened))
{
  unset($obj->notdefiened);  
}
echo $obj->notdefiened;
?>


Output:
1
2
3
4
5
6
7

get from array
set data in array
get from arrayr u there??
chking if set
unseting
get from array


Create a new paste based on this one


Comments: