Re: php5: read-only variables

From: Date: Mon, 09 Feb 2004 09:18:33 +0000
Subject: Re: php5: read-only variables
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-177193@lists.php.net to get a copy of this message
Vivian Steller writes: > hello, > talking about php5, i'm missing "read-only" attributes/variables for > classes/objects. i.e. this would be very useful for implementing the new > DOM Level 3 Interfaces as given in http://www.w3.org/TR/2003 > CR-DOM-Level-3-Core-20031107/idl-definitions.html . ... > If anybody has an acceptable fake-solution, please let me know... > thanks I don't think there's a good reason not to have read-only members. Java and C++ don't either, but Eiffel does. You fake it by declaring them private and writing a get_foo() method for each one. Done this way it it is tedious and ugly, but by overloading member access with the __get( $name ) method, you can achieve the same functionality with fewer lines of code and a cleaner interface to client classes. See under overloading in http://www.php.net/zend-engine-2.php for examples. -- __o Alex Farran _`\<,_ Analyst / Programmer (_)/ (_) www.alexfarran.com

« previous php.general (#177193) next »