From:             e dot sand at elisand dot com
Operating system: Irrelevant
PHP version:      5.2.9
PHP Bug Type:     Feature/Change Request
Bug description:  Allow read/write setting for class members

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 bug report at http://bugs.php.net/?id=47881&edit=1
-- 
Try a CVS snapshot (PHP 5.2):        
http://bugs.php.net/fix.php?id=47881&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):        
http://bugs.php.net/fix.php?id=47881&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):        
http://bugs.php.net/fix.php?id=47881&r=trysnapshot60
Fixed in CVS:                        
http://bugs.php.net/fix.php?id=47881&r=fixedcvs
Fixed in CVS and need be documented: 
http://bugs.php.net/fix.php?id=47881&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=47881&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=47881&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=47881&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=47881&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=47881&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=47881&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=47881&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=47881&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=47881&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=47881&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=47881&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=47881&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=47881&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=47881&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=47881&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=47881&r=mysqlcfg

Reply via email to