Re: The inconsistencies/flaws of PHP5's object model

From: Date: Sat, 21 Nov 2009 09:59:26 +0000
Subject: Re: The inconsistencies/flaws of PHP5's object model
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-46145@lists.php.net to get a copy of this message
On 18.11.2009, at 09:23, Jingcheng Zhang wrote: > Hello internals, > > I've just occured a syntax problem in the following script: > > <?php > class C { > public $n = 1; > } > $o = new C(); > $o->f = function () use ($o) { > echo $o->n; > }; > $o->f(); > ?> > > The result of this script is "Fatal Error: Call to undefined method C::f()". > I don't know this is the expected result. After trying more tests of > adding/removing properties on the fly, I concluded these > inconsistencies/flaws: > > 1. There is no way to add/remove instance-level members (both properties and > methods) to class dynamically, but a way to add them to instance itself, > which is a little buggy as above codes turns out; > 2. There is no way to add/remove static members dynamically either; > 3. There are __get(), __set(), __call() for instance-level members, and > __callStatic() for static methods, but lacks __getStatic() and __setStatic() > for static properties; > 4. While using static class as object (general concept of "object", not > "instance" here), it's extremly complex to simulate "prototype > object", as > static members simply do'not duplicate themselves at all while inheriting, > therefore all of the child classes share a single static member of the > parent class; > 5. The inheritance rule of static member is not well documented, developers > has to try it out themselves; > 6. Static methods are allowed in interfaces, but not allowed in abstract > class, which breaks the rule of abstraction; > 7. An interface which has only static methods cannot ensure static methods > in a class which implements it. > > Sorry to raise so many complaint, but these inconsistencies bring me a big > headache when developing. I would like to hear the design rules of PHP5's > object model, at least, the explanations of the above inconsistencies. > Thanks very much! > It feels like a lot of these points have been raised before (especially in the thread where the addition of closures where discussed). It would be nice if you could turn this into an RFC, maybe digg a bit in the recent archives as well. This would help to make it easier to find out why something wasnt done etc. This helps in avoiding redundant discussions, but also helps people if after all certain changes do become possible/feasible eventually. regards, Lukas Kahwe Smith mls@pooteeweet.org

« previous php.internals (#46145) next »