Intercepting Property Access with __get() and __set() (PHP 5 Only) : __get « Class « PHP






Intercepting Property Access with __get() and __set() (PHP 5 Only)

 
<?php
class TimeThing {
  function __get( $arg ) {
    if ( $arg == "time" ) {
      return getdate();
    }
  }

  function __set( $arg, $val ) {
    if ( $arg == "time" ) {
      trigger_error( "cannot set property $arg" );
      return false;
    }
  }
}

$cal = new TimeThing();
print $cal->time['mday']."/";
print $cal->time['mon']."/";
print $cal->time['year'];

?>
  
  








Related examples in the same category

1.__get( ) specifies what to do if an unknown property is read from within your script
2.Enforcing property access using magic accessor methods