|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-12-29 20:33 UTC] zyss at mail dot zp dot ua
[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
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 08 21:00:02 2025 UTC |
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..