note 82896 deleted from language.oop5.overloading by cmb
| From: | cmb@php.net | Date: | Sun, 29 Dec 2019 10:12:58 +0000 |
| Subject: | note 82896 deleted from language.oop5.overloading by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213663@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
This is a generic implementation to use getter, setter, issetter and unsetter for your own classes.
<?php
abstract class properties
{
public function __get( $property )
{
if( ! is_callable( array($this,'get_'.(string)$property) ) )
throw new BadPropertyException($this, (string)$property);
return call_user_func( array($this,'get_'.(string)$property) );
}
public function __set( $property, $value )
{
if( ! is_callable( array($this,'set_'.(string)$property) ) )
throw new BadPropertyException($this, (string)$property);
call_user_func( array($this,'set_'.(string)$property), $value );
}
public function __isset( $property )
{
if( ! is_callable( array($this,'isset_'.(string)$property) ) )
throw new BadPropertyException($this, (string)$property);
return call_user_func( array($this,'isset_'.(string)$property) );
}
public function __unset( $property )
{
if( ! is_callable( array($this,'unset_'.(string)$property) ) )
throw new BadPropertyException($this, (string)$property);
call_user_func( array($this,'unset_'.(string)$property) );
}
}
?>