php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #54019 synthesize class property setter/getter feature request
Submitted: 2011-02-14 18:40 UTC Modified: 2015-03-20 15:11 UTC
Votes:8
Avg. Score:4.2 ± 1.4
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:3 (75.0%)
From: monte at ohrt dot com Assigned:
Status: Duplicate Package: *General Issues
PHP Version: Irrelevant OS: n/a
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: monte at ohrt dot com
New email:
PHP Version: OS:

 

 [2011-02-14 18:40 UTC] 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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-14 19:09 UTC] 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.
 [2015-03-20 15:11 UTC] levim@php.net
-Status: Open +Status: Duplicate -Package: Unknown/Other Function +Package: *General Issues
 [2015-03-20 15:11 UTC] levim@php.net
In principle this is a duplicate of bug #49526.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 28 10:01:31 2024 UTC