Petar Nedyalkov wrote:
On Tuesday 25 April 2006 14:30, Edin Kadribasic wrote:
Hi,
I was wondering if someone could enlighten me why it is not possible to
create on-the-fly static properties:
php -r 'class foo{}; foo::$bar = 1;'
Fatal error: Access to undeclared static property: foo::$bar in Command
line code on line 1
This totally breaks the capsulation in the OO paradigm, so I find it the right
behaviour. Taking apart the fact that there's no compilation in PHP, it also
prevents capsulation and making a member variable of an object available only
after it's declaration in the class (except for stdClass) is correct for me.
I see this as "You can't redefine the model at runtime".
Rubys allows exactly that and I'm sure your not going to say that Ruby is not
an OO
language - Javascript likewise, in that it allows runtime definition/extension
of
the model (granted it's prototype based rather than class based).
(anyone with the argument that PHP!=Ruby or PHP!=Javascript might consider that
PHP!="the OO paradigm")
I don't think the Fatal Error mentioned above is, from a endusers' POV,
what would be expected given the ability to define non-static properties on the
fly...
If I had to guess as to what kind of error was raised I would have put my money
on
E_STRICT - i.e. 'we don't recommend this way of doing things, but it doesn't
hurt the
engine per se'
having said that I have never needed to define static properties on the fly, so
it's
all rather academic. :-)
Was this not possible because of the engine implementation of the static
properties?
Edin
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php