php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #47881 Allow read/write setting for class members
Submitted: 2009-04-02 17:58 UTC Modified: 2018-05-05 20:03 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: e dot sand at elisand dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 5.2.9 OS: Irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: e dot sand at elisand dot com
New email:
PHP Version: OS:

 

 [2009-04-02 17:58 UTC] e dot sand at elisand dot com
Description:
------------
I believe having the ability to define read & write permissions on class members would help with certain problems encountered when currently trying to implement similar features using __get() and __set().

I would like to propose that three "flags" be defined and would be used with the public, protected and private declarations.  The flags would be ro (read-only), wo (write-only) and rw (read-write; for completeness).  They would be prepended (or appended) to a visibility declarations, for example: ro_public, rw_protected or wo_private.

These three flags would allow more control over member access than attempting to use __get() and/or __set() which, to achieve similar results, could require many lines of additional logic and code.  As it is currently in PHP 5.2.x, due to the implementation of trigger_error() (in that you cannot perfectly mimic an internal E_ERROR), it is not possible to transparently implement features such as what I am proposing here.

Setting the various flags on the different visibility declarations would have differing results.  I will (attempt) to explain how these flags would function depending on visibility.

* Setting ro/wo on a public declaration would mean that public access can only read/write to that member; access by direct and extended classes of that member would be unrestricted.
* Setting ro/wo on a protected declaration would mean that extended classes can only read/write to that member; public access is still prohibited and direct class access is still unrestricted.
* Setting ro/wo on a private declaration would mean that direct class access is read/write only; public and extended class access is still prohibited.

Note: from the examples, you can see why the "rw" flag isn't required - I mentioned it simply for completeness if it would make sense to allow people to define it, otherwise it can be omitted since it is simply the "default" access permission.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-05-05 20:03 UTC] requinix@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: *General Issues
 [2018-05-05 20:03 UTC] requinix@php.net
A change of this scope requires using the RFC process. https://wiki.php.net/rfc/howto

But if anyone wants to take charge of the idea, please familiarize yourself with existing discussions about this subject that I assure you have already taken place.
https://marc.info/?l=php-internals&r=1&w=2
https://wiki.php.net/rfc/readonly_properties
https://wiki.php.net/rfc/propertygetsetsyntax-v1.2

Closing wontfix due to age and pessimism. We can reopen if there's renewed interest in this idea.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 04:01:30 2024 UTC