note 68053 deleted from language.oop5.overloading by cmb
| From: | cmb@php.net | Date: | Sun, 03 Mar 2019 11:36:08 +0000 |
| Subject: | note 68053 deleted from language.oop5.overloading by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-210307@lists.php.net to get a copy of this message | ||
Note Submitter: mnaul at nonsences dot angelo dot edu
----
This is just my contribution. It based off of many diffrent suggestions I've see thought the
manual postings.
It should fit into any class and create default get and set methods for all you member variables.
Hopfuly its usefull.
<?php
public function __call($name,$params)
{
if( preg_match('/(set|get)(_)?/',$name) )
{
if(substr($name,0,3)=="set")
{
$name = preg_replace('/set(_)?/','',$name);
if(property_exists(__class__,$name))
{
$this->{$name}=array_pop($params);
return true;
}
else
{
//call to class error handler
return false;
}
return true;
}
elseif(substr($name,0,3)=="get")
{
$name = preg_replace('/get(_)?/','',$name);
if(property_exists(__class__,$name) )
{
return $this->{$name};
}
else
{
//call to class error handler
return false;
}
}
else
{
//call to class error handler
return false;
}
}
else
{
die("method $name dose not exist\n");
}
return false;
}