Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46095 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74783 invoked from network); 19 Nov 2009 03:16:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Nov 2009 03:16:03 -0000 Authentication-Results: pb1.pair.com header.from=diogin@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=diogin@gmail.com; spf=pass; sender-id=pass 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:59572] helo=mail-px0-f186.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E8/50-06827-178B40B4 for ; Wed, 18 Nov 2009 22:16:02 -0500 Received: by pxi16 with SMTP id 16so1221816pxi.29 for ; Wed, 18 Nov 2009 19:15:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=ldWND/DyucsssG4E3Q0FzVYrJQXpvYq/C8/uXRqke1U=; b=RaBLZ863jLjCmO8QxRnkXkNI5GOoPGy7Fxfd7Jxd6v8CutGeNf/8NIRXjJVDr8Dppb Vlx7ZG4QvcjmzaXvCVUwFZUWzxbc0ygGZYo1YBrd5pomLWRvZAvdXxrlBCY6MiK4q3AI YMmcAuA+jmdEamq/MMQK3WiKbMIPHhpLafE4s= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=KsiYP9GhG5A7thbZG7h9tooOZwaj3J3eYeXTC4PxkTaPSyr2xlA2G4r/5dEDrmuKk4 gEZ4Mk9eaWVVOfTd3pnS0xftljQ0ExiW5+UR3cMEYDx9nmFj67yC+viDsgbTIaQ5Q6SS I5yAeol70eKeGwCpXs0saVZBeMOyHABsraN4M= MIME-Version: 1.0 Received: by 10.143.137.2 with SMTP id p2mr1374011wfn.136.1258600558919; Wed, 18 Nov 2009 19:15:58 -0800 (PST) In-Reply-To: <4B045234.1010804@zend.com> References: <4B045234.1010804@zend.com> Date: Thu, 19 Nov 2009 11:15:58 +0800 Message-ID: To: Stanislav Malyshev Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=000e0cd4ce923a80aa0478b0c7d6 Subject: Re: [PHP-DEV] The inconsistencies/flaws of PHP5's object model From: diogin@gmail.com (Jingcheng Zhang) --000e0cd4ce923a80aa0478b0c7d6 Content-Type: text/plain; charset=ISO-8859-1 Hello Stanislav, 2009/11/19 Stanislav Malyshev > Hi! > > Yes, this is the expected result. PHP is not Javascript, sorry :) Methods > and properties are different things in PHP, so the syntax assumes you refer > to method when you call $o->f(). You could use other syntaxes if you need to > use a property as callable (see call_user_function, etc.). > > Before PHP 5.3, $className::$methodName() is not allowed, people who needs this call should use call_user_func(array($className, $methodName)) instead, which is ugly and verbose. Since PHP 5.3 adds closure support, I think the syntax "$o->f()" should also check whether "f" is a closure, if it is, then call it. > > 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; >> > > It is not "buggy", it is how the language is - class is a fixed template, > object is a mutable instance of this template. > > As PHP is a dynamic language, it might be acceptable to dynamically change the "fixed template" nature of class, especially when programming PHP in prototype-based way by using class as "object" (which I think is much natural to class-based programming in PHP since "class" is a static concept, while "object" is a dynamic concept which suits PHP interpreter's running model perfectly). > > 3. There are __get(), __set(), __call() for instance-level members, and >> __callStatic() for static methods, but lacks __getStatic() and >> __setStatic() >> for static properties; >> > > That may be added if somebody provides a good patch. > I found this path provided by Lars Strojny in wiki page ( http://wiki.php.net/rfc/static-classes): http://lars.schokokeks.org/php/static-classes-002.diff I'm not sure wether this patch is good. > > 4. While using static class as object (general concept of "object", not >> "instance" here), it's extremely 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; >> > > That's how static members work - they belong to the defining class. > > > 6. Static methods are allowed in interfaces, but not allowed in abstract >> class, which breaks the rule of abstraction; >> > > You can have static functions in abstract classes. What you can not have is > abstract static functions, because it makes little sense - static function > belongs to the class, so if it's abstract - meaning needs to be redefined - > then what exactly you are defining? You'll define static functions in child > classes anyway and you'll be calling them explicitly by class name (i.e. > ChildClass::foo, not BaseClass::foo). > > Yes I mean abstract static function here, sorry for my typo. Abstract static function is meaningful: You can force child class to implement it, and combining it with "Late Static Binding" one can implement "Template Method Pattern" in prototype-based way here: This is equivalent to "Template Method Pattern" in instance-level way. In addition, interfaces and abstract classes are both abstraction of a specific API, methods declared in interfaces should be totally identical to methods declared in abstract classes, aren't they? One can implements an interface with an abstract class, and get an abstract static function in abstract class: isAbstract()); ?> It is meaningless to forbid abstract static function. > > 7. An interface which has only static methods cannot ensure static methods >> in a class which implements it. >> > > I'm not sure what you mean here, could you provide a short code example > that you think should be working and doesn't? > > For example: This result is more or less expected since type hinting only works on variable types, and the argument 'c' is a string, but as a type, the interface i cannot hint the fact that class c "is a type of i". Thanks for your patient reply! > > -- > Stanislav Malyshev, Zend Software Architect > stas@zend.com http://www.zend.com/ > (408)253-8829 MSN: stas@zend.com > -- Best regards, Jingcheng Zhang P.R.China --000e0cd4ce923a80aa0478b0c7d6--