Re: RE:Class::? - accessing data, no success...
| From: | Kristian Köhntopp | Date: | Wed, 05 Jul 2000 12:50:22 +0000 |
| Subject: | Re: RE:Class::? - accessing data, no success... | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-23558@lists.php.net to get a copy of this message | ||
Stanislav Malyshev wrote:
> That doesn't work this way. $class::var should be some variable, which can
> be used in any expression. The question is - what variable is it? Where it
> comes from?
Some definitions for a language that is not quite like Zend/PHP4:
Let C by a class,
let $o = new C; be an object, an instance of C.
The object $o have some instance variables named
o1, o2, o3. At the moment, these are being addressed in
PHP using the following arrow syntax:
$o->o1 = "something";
$o->o2 = 17;
...
The class C could have some class variables c1, c2, c3.
These are variables which belong to the class, not the
object and are shared by all instances of C. One could
probably write
$C::c1 = "something";
$C::c2 = 17;
...
to address these values. Using
C::c1 = "something";
...
would be a bad idea because PHP relies on the $ prefix
for variable names to do string interpolation.
To make things consistent, the instance methods im1, im2,
im3 and so on of $o are being called using
$o->im1();
...
and so on. Thus, writing
C::cm1();
...
to call the class methods as we currently do in PHP would
be inconsistent. It should be orthogonal, thus the syntax
should me
$C::cm1();
...
to call class methods, if possible.
Now, what are class methods and what are class variables?
A class method is a method that can be called without having
an instance of that class. This method should not be able to
use instance methods, as there is no instance. It should not
be able to use instance variables, for the same reason. It
may be possible to use "$this" internally in a class method
to refer to other class methods of the same class, and to
refer to other class variables of that class. This would be
useful, as there will be less references to the hardcoded
classname in the code - the class name should be used only
in one place, the class definition "class <name>" or
"class <name> extends <name'>".
I assume this is implemented by making a class an object, too
(So of what class is the class object? Metaclass! So is
Metaclass, terminating the recursion. Have a look at the
Smalltalk object model for detailed information - this is
an bytecode interpreted single inheritance language just
as PHP4, so it should be adequate.)
If all classes are instances of Metaclass, they would inherit
a number of methods from Metaclass, and these methods would
be what is currently available as Zend functions such as
get_class() and get_parent_class. Even new could be a
method of Metaclass, leading to constructs such as
$o = $C::new();
but this is for the OOP stasi only. It shows how orthogonal
things can be in such a model.
--
Kristian Köhntopp, NetUSE AG Siemenswall, D-24107 Kiel
Tel: +49 431 386 436 00, Fax: +49 431 386 435 99
Using PHP3? See our web development library at http://phplib.netuse.de/