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
{
    /**
     * @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
}
?>

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"?

This is ofcourse overly complicated. A better workable solution would be -
  without breaking BC (suggestions for syntax here are very welcome):

<?php
class Base
{
    abstract public $x = 1;

    function __get($name)
    {
        if (!self::isVirtual($name))) {
            /* throw error */
        }
    }
}

$b = new Base();
echo $b->foo;
?>

How about a __have_prop() method that you can call to find out if a certain virtual property exists?

-Andrei

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

Reply via email to