note 71383 added to language.oop5.overloading
| From: | mhherrera31athotmaildotcom at osu1 dot php dot net | Date: | Sat, 25 Nov 2006 18:11:06 +0000 |
| Subject: | note 71383 added to language.oop5.overloading | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-120074@lists.php.net to get a copy of this message | ||
example for read only properties in class object. Lets you manage read only properties with var
names like $ro_var.
The property must be PRIVATE, otherwise the overload method __get doesn't be called.
class Session {
private $ro_usrName;
function __construct (){
$this->ro_usrName = "Marcos";
}
function __set($set, $val){
if(property_exists($this,"ro_".$set))
echo "The property '$set' is read only";
else
if(property_exists($this,$set))
$this->{$set}=$val;
else
echo "Property '$set' doesn't exist";
}
function __get{$get}{
if(property_exists($this,"ro_".$get))
return $this->{"ro_".$get};
else
if(property_exists($this,$get))
return $this->{$get};
else
echo "Property '$get' doesn't exist";
}
}
----
Server IP: 201.216.232.3
Probable Submitter: 201.231.72.232
----
Manual Page -- http://www.php.net/manual/en/language.oop5.overloading.php
Edit -- https://master.php.net/note/edit/71383
Del: integrated -- https://master.php.net/note/delete/71383/integrated
Del: useless -- https://master.php.net/note/delete/71383/useless
Del: bad code -- https://master.php.net/note/delete/71383/bad+code
Del: spam -- https://master.php.net/note/delete/71383/spam
Del: non-english -- https://master.php.net/note/delete/71383/non-english
Del: in docs -- https://master.php.net/note/delete/71383/in+docs
Del: other reasons-- https://master.php.net/note/delete/71383
Reject -- https://master.php.net/note/reject/71383
Search -- https://master.php.net/manage/user-notes.php