Re: Property Overloading RFC
| From: | Andrei Zmievski | Date: | Wed, 03 Aug 2005 23:52:50 +0000 |
| Subject: | Re: Property Overloading RFC | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-17520@lists.php.net to get a copy of this message | ||
On Aug 2, 2005, at 6:05 AM, Derick Rethans wrote:
Solutions: - For problem 1. we can introduce a keyword (or use an existing one) to define that it is a virtual property ('abstract' or 'virtual' come to mind). When declaring it like this it's easy to document, and we can also implement visibility for those virtual properties. Marcus already has a patch for this somewhere, which uses the "abstract" keyword for this purpose: <?php class Base {The whole point of these "virtual" properties is that their names can be parameterized. If you have 1000 of these variables (in a DB or somewhere), how would you declare them as "abstract" or "virtual"?/** * @var int Contains all X */ abstract public $x = 1;/** * @var int Contains all Y */ abstract protected $y = 2;// abstract private $z = 3; abstract properties cannot be private} ?>
This is ofcourse overly complicated. A better workable solution would be - without breaking BC (suggestions for syntax here are very welcome): <?php class Base {How about a __have_prop() method that you can call to find out if a certain virtual property exists? -Andreiabstract public $x = 1;function __get($name) { if (!self::isVirtual($name))) { /* throw error */ } }} $b = new Base(); echo $b->foo; ?>