Edit report at http://bugs.php.net/bug.php?id=54019&edit=1
ID: 54019
User updated by: monte at ohrt dot com
Reported by: monte at ohrt dot com
Summary: synthesize class property setter/getter feature
request
Status: Open
Type: Feature/Change Request
Package: Unknown/Other Function
Operating System: n/a
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
This could also speed up the access to stub setters/getters (?), as
manually
created methods are much slower than direct property access.
Previous Comments:
------------------------------------------------------------------------
[2011-02-14 18:40:38] monte at ohrt dot com
Description:
------------
This is a take from the objective-c language, and may prove useful in
future
releases of PHP.
Currently, to generate generic setters/getters for class properties,
this must
be done manually in the class declaration:
class Foo {
public $bar
function bar() {
return $this->bar;
}
function setBar($val) {
$this->bar = $val;
}
}
This can be a tedious task when there are many properties, and clutter
up the
class. Using the __call() magic function for manual pseudo-synthesized
functions
is a complexity and extra wrapper call that could be avoided.
Feature request: the ability to have PHP automatically synthesize
generic
setters/getters for properties. You would specify which properties are
synthesized. Syntax idea:
class Foo {
synthesize public $bar;
// bar() and setBar() are now automatically synthesized by PHP
}
Manual overrides to these synthesized methods are permissible, in case a
non-
generic method is required. This feature would greatly simplify
boiler-plate
setter/getter setup, and avoid the overhead of using __call() as a
wrapper to
create a manual psuedo-synthesize functionality. PHP IDE's would be able
to
identify synthesized properties for auto-completion of available
setter/getter
methods.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=54019&edit=1