Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46078 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5544 invoked from network); 18 Nov 2009 08:23:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Nov 2009 08:23:45 -0000 Authentication-Results: pb1.pair.com smtp.mail=diogin@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=diogin@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.186 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: diogin@gmail.com X-Host-Fingerprint: 209.85.216.186 mail-px0-f186.google.com Received: from [209.85.216.186] ([209.85.216.186:41663] helo=mail-px0-f186.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3F/30-03426-11FA30B4 for ; Wed, 18 Nov 2009 03:23:45 -0500 Received: by pxi16 with SMTP id 16so611639pxi.29 for ; Wed, 18 Nov 2009 00:23:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=0QUbAs4vWfyuse8YdW2UBjhf0AH3xNITCEreAh1HSM4=; b=BRU1VqlE0FymYAE4xRGfFzdLMrvopfx3kYPCOYzUj8q6z5qO+cMqBv1HWYanp4YmnV p2WLHSZDVd47TZAiZAU5meoUyvhR0ipjfDtJie6PQE4k8CjcbHZvPVYqkxqv820511xR FwcnkzLIYirr+jRT3hC8VCOdz3zUT6H9Qcjbs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=kQjmRYSZmlE4iGbKMEQYwQSYbwUhQQGFjMPem7ePC/uL3ijF9knbUo1CQfVVwL9gCd 5WXPp4n7tjFmYNRY5hz/he/LB8CrrEU/wlNvRNEl5suj8dCxzIX40S5dSTErN9ILFoVQ mNjYGEIGDgbAh6lrufXyXb2Wh1I8p4vdOBJcc= MIME-Version: 1.0 Received: by 10.142.74.3 with SMTP id w3mr1243809wfa.191.1258532620826; Wed, 18 Nov 2009 00:23:40 -0800 (PST) Date: Wed, 18 Nov 2009 16:23:40 +0800 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary=001636e1fb61cd79050478a0f589 Subject: The inconsistencies/flaws of PHP5's object model From: diogin@gmail.com (Jingcheng Zhang) --001636e1fb61cd79050478a0f589 Content-Type: text/plain; charset=ISO-8859-1 Hello internals, I've just occured a syntax problem in the following script: 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! -- Best regards, Jingcheng Zhang P.R.China --001636e1fb61cd79050478a0f589--