php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #46949 New "property" keyword token
Submitted: 2008-12-26 23:29 UTC Modified: 2012-02-26 08:49 UTC
Votes:4
Avg. Score:4.8 ± 0.4
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:3 (75.0%)
From: fatih at tullab dot com Assigned: rasmus (profile)
Status: Closed Package: *General Issues
PHP Version: 5.3.0alpha3 OS: Windows+Linux
Private report: No CVE-ID: None
 [2008-12-26 23:29 UTC] fatih at tullab dot com
Description:
------------
Hi,
It is hard to write and read this getter and setter codes:

private $_aProperty = "";

public getAProperty(){
    return $this->_aProperty;
}

public setAProperty($value){
    $this->_aProperty = $value;
}

And if we want to use this getter and setter, we will write like this:
$value = $anObject->getAProperty();
$anObject->setAProperty("something");

It is hard to read and confusing because of "set" and "get" prefixes. 
But if we have a "property" keyword, we can use same name without "get" and "set" prefixes.

class AClass
{
private $_name;
protected getName(){
    return $this->_name;
}
protected setName($value){
    $this->_name = $value
}
/*****/
public property Name get getName set setName;
/*****/
}

anObject = new AClass();
anObject->Name = "something"; //triggering setName function.
echo anObject->Name; //triggering getName function.

Regards..


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-29 20:33 UTC] zyss at mail dot zp dot ua
Agree, much more convenient. Delphi rules :-)
 [2012-02-26 08:49 UTC] rasmus@php.net
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: rasmus
 [2012-02-26 08:49 UTC] rasmus@php.net
Seems to me that __get/__set accomplishes the same thing.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 12:01:29 2024 UTC