php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #64204 Read only and write once paramater visibility
Submitted: 2013-02-13 15:12 UTC Modified: 2013-02-13 16:34 UTC
From: andy at mrhunt dot co dot uk Assigned:
Status: Wont fix Package: Unknown/Other Function
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2013-02-13 15:12 UTC] andy at mrhunt dot co dot uk
Description:
------------
This is a hopefully simple request to add an extra visibility type into classes to 
allow for paramaters that can be read outside the class like with public but can 
only be written too inside as with protected. I've put a sample of how I think 
this should work below to hopefully give you a better idea of this.

Test script:
---------------
class Test
{
  readonly $param_ro;

  public funcion test()
  {
    $this->param_ro = 'test-ro'; // Works
  }
}
$test = new Test();

echo $test->param_ro; // Works

$this->param_ro = 'test'; // Fails


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-02-13 16:34 UTC] johannes@php.net
-Status: Open +Status: Wont fix
 [2013-02-13 16:34 UTC] johannes@php.net
No, this is not easy, mind cases like this:

$test = new Test();
$foo = &$test->param_ro;
$foo = 'test';

Our current discussion state is more around accessors, while that's not yet accepted either: https://wiki.php.net/rfc/propertygetsetsyntax-v1.2
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 10 04:01:31 2024 UTC