Possible Duplicate:
PHP Readonly Properties?
I want a property to be publicly visible:
echo $object->prop;
but I don't want to be modifiable.
Are there other options to make this happen, besides using __get
?
Possible Duplicate:
PHP Readonly Properties?
I want a property to be publicly visible:
echo $object->prop;
but I don't want to be modifiable.
Are there other options to make this happen, besides using __get
?
Other ways I can think of:
__set()
function and ignore the setting.Hope this helps :)
Are there other options to make this happen, besides using __get?
No, but there is feature request for it: https://bugs.php.net/bug.php?id=46506 so you can vote for importance of it and hope that this will be resolved in near future.
But I don't think it will be near future since this feature will create a lot of confusion, like objects stored in properties - they are only references to the object, so making them visible allows you to operate on it's methods / properties.
As for now, creating proper getter for every property, that you want to be read-only, seems to be the best solution.