I'll probably be lynched for bringing up this subject again, since it caused a long discussion a year ago. Anyway I look in the archives and there was never a real conclusion made, so I'm bringing it up again. This time for a feature I personally would like to see in PHP 6.

Very often I want to be able to be get a property publicly, while only being able to set it within the class. You can solve this by using a getPropery() method or by using __get($property), but this feels more like a workaround. I think the private/public state of properties is becoming more important now that using public frameworks is becoming main stream. Therefor I believe this would be a good addition.

Unfortunately, there are a few caveats to this when used with objects, resources, and arrays. The simplest way to explain would be to show some sample code:

class foo {
  public $bar = 'baz';
}

class myclass {
  protected_write $f;
  private_write $fp;

  function __construct() {
    $this->f = new foo;

    $this->fp = fopen('somefile.txt', 'r');
  }
}

$m = new myclass;

$F = $myclass->f;
$F->bar = 'blong';

$FP = $myclass->fp;
fclose($FP);


The explanation of arrays is a bit more involved, but it's got some gotchas too...

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to