Req #54019 [Opn->Dup]: synthesize class property setter/getter feature request

From: Date: Fri, 20 Mar 2015 15:11:37 +0000
Subject: Req #54019 [Opn->Dup]: synthesize class property setter/getter feature request
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191489@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=54019&edit=1 ID: 54019 Updated by: levim@php.net Reported by: monte at ohrt dot com Summary: synthesize class property setter/getter feature request -Status: Open +Status: Duplicate Type: Feature/Change Request -Package: Unknown/Other Function +Package: *General Issues Operating System: n/a PHP Version: Irrelevant Block user comment: N Private report: N New Comment: In principle this is a duplicate of bug #49526. Previous Comments: ------------------------------------------------------------------------ [2011-02-14 19:09:57] monte at ohrt dot com This could also speed up the access to stub setters/getters (?), as manually created methods are much slower than direct property access. ------------------------------------------------------------------------ [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 https://bugs.php.net/bug.php?id=54019&edit=1

« previous php.bugs (#191489) next »