Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46145 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 63772 invoked from network); 21 Nov 2009 09:59:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Nov 2009 09:59:30 -0000 Authentication-Results: pb1.pair.com header.from=mls@pooteeweet.org; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=mls@pooteeweet.org; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain pooteeweet.org from 88.198.8.16 cause and error) X-PHP-List-Original-Sender: mls@pooteeweet.org X-Host-Fingerprint: 88.198.8.16 bigtime.backendmedia.com Linux 2.6 Received: from [88.198.8.16] ([88.198.8.16:47250] helo=bigtime.backendmedia.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8A/03-40936-20AB70B4 for ; Sat, 21 Nov 2009 04:59:30 -0500 Received: from localhost (unknown [127.0.0.1]) by bigtime.backendmedia.com (Postfix) with ESMTP id D40314144059; Sat, 21 Nov 2009 10:00:32 +0000 (UTC) X-Virus-Scanned: amavisd-new at backendmedia.com Received: from bigtime.backendmedia.com ([127.0.0.1]) by localhost (bigtime.backendmedia.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id atBF+GYrikBI; Sat, 21 Nov 2009 11:00:32 +0100 (CET) Received: from [192.168.0.151] (217-162-131-234.dclient.hispeed.ch [217.162.131.234]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: mls@pooteeweet.org) by bigtime.backendmedia.com (Postfix) with ESMTP id C87D74144009; Sat, 21 Nov 2009 11:00:31 +0100 (CET) Mime-Version: 1.0 (Apple Message framework v1077) Content-Type: text/plain; charset=us-ascii In-Reply-To: Date: Sat, 21 Nov 2009 10:59:26 +0100 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <34A05C5C-7F34-4B92-A489-3F35349B905E@pooteeweet.org> References: To: Jingcheng Zhang X-Mailer: Apple Mail (2.1077) Subject: Re: [PHP-DEV] The inconsistencies/flaws of PHP5's object model From: mls@pooteeweet.org (Lukas Kahwe Smith) On 18.11.2009, at 09:23, Jingcheng Zhang wrote: > Hello internals, >=20 > I've just occured a syntax problem in the following script: >=20 > class C { > public $n =3D 1; > } > $o =3D new C(); > $o->f =3D function () use ($o) { > echo $o->n; > }; > $o->f(); > ?> >=20 > 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: >=20 > 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. >=20 > 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! >=20 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