note 98267 added to language.oop5.properties
| From: | zzzzBov at osu1 dot php dot net | Date: | Sat, 05 Jun 2010 04:21:52 +0000 |
| Subject: | note 98267 added to language.oop5.properties | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-169901@lists.php.net to get a copy of this message | ||
Do not confuse php's version of properties with properties in other languages (C++ for
example). In php, properties are the same as attributes, simple variables without functionality.
They should be called attributes, not properties.
Properties have implicit accessor and mutator functionality. I've created an abstract class
that allows implicit property functionality.
<?php
abstract class PropertyObject
{
public function __get($name)
{
if (method_exists($this, ($method = 'get_'.$name)))
{
return $this->$method();
}
else return;
}
public function __isset($name)
{
if (method_exists($this, ($method = 'isset_'.$name)))
{
return $this->$method();
}
else return;
}
public function __set($name, $value)
{
if (method_exists($this, ($method = 'set_'.$name)))
{
$this->$method($value);
}
}
public function __unset($name)
{
if (method_exists($this, ($method = 'unset_'.$name)))
{
$this->$method();
}
}
}
?>
after extending this class, you can create accessors and mutators that will be called automagically,
using php's magic methods, when the corresponding property is accessed.
----
Server IP: 69.147.83.197
Probable Submitter: 74.74.171.1
----
Manual Page -- http://www.php.net/manual/en/language.oop5.properties.php
Edit -- https://master.php.net/note/edit/98267
Del: integrated -- https://master.php.net/note/delete/98267/integrated
Del: useless -- https://master.php.net/note/delete/98267/useless
Del: bad code -- https://master.php.net/note/delete/98267/bad+code
Del: spam -- https://master.php.net/note/delete/98267/spam
Del: non-english -- https://master.php.net/note/delete/98267/non-english
Del: in docs -- https://master.php.net/note/delete/98267/in+docs
Del: other reasons-- https://master.php.net/note/delete/98267
Reject -- https://master.php.net/note/reject/98267
Search -- https://master.php.net/manage/user-notes.php