php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #34194 Real properties in PHP classes
Submitted: 2005-08-19 16:41 UTC Modified: 2010-12-22 03:52 UTC
Votes:7
Avg. Score:4.6 ± 0.7
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
From: stochnagara at hotmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5CVS-2005-08-19 (CVS) OS:
Private report: No CVE-ID:
 [2005-08-19 16:41 UTC] stochnagara at hotmail dot com
Description:
------------
I think that it would be nice to have real properties present in PHP. I mean properties like those in C# but a little more flexible by allowing getter and setter to have different visibility. See sample code below:


Reproduce code:
---------------
class person {
  public $firstName, $lastName;

  public getter fullName { // may also have ()
   return "{$this->firstName} {$this->lastName}";
  }

  public setter fullName ($value) { // may also not have ($value) but a special var.
   list ($this->firstName, $this->lastName) = explode (' ', $value, 2);
  }
}

 $p = new person;
 $p->fullName = "Foo bar";
 echo $p->firstName . "\n";
 echo $p->lastName . "\n";
 echo $p->fullName . "\n";


Expected result:
----------------
Foo
bar
Foo bar

Actual result:
--------------
n/a

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-22 03:52 UTC] johannes@php.net
-Status: Open +Status: Bogus -Package: Feature/Change Request +Package: *General Issues
 [2010-12-22 03:52 UTC] johannes@php.net
This request is covered by this RFC: http://wiki.php.net/rfc/propertygetsetsyntax
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Mon Apr 21 07:02:06 2014 UTC