Req #47881 [Opn->Wfx]: Allow read/write setting for class members
Edit report at https://bugs.php.net/bug.php?id=47881&edit=1
ID: 47881
Updated by: requinix@php.net
Reported by: e dot sand at elisand dot com
Summary: Allow read/write setting for class members
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: *General Issues
Operating System: Irrelevant
PHP Version: 5.2.9
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2009-04-02 17:58:29] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=47881&edit=1
Thread (2 messages)