Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46109 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 26804 invoked from network); 19 Nov 2009 18:18:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Nov 2009 18:18:56 -0000 Authentication-Results: pb1.pair.com header.from=stas@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=stas@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 212.25.124.185 as permitted sender) X-PHP-List-Original-Sender: stas@zend.com X-Host-Fingerprint: 212.25.124.185 il-mr1.zend.com Received: from [212.25.124.185] ([212.25.124.185:48109] helo=il-mr1.zend.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 79/DB-65535-D0C850B4 for ; Thu, 19 Nov 2009 13:18:56 -0500 Received: from us-gw1.zend.com (unknown [192.168.16.5]) by il-mr1.zend.com (Postfix) with ESMTP id 89D69504B6; Thu, 19 Nov 2009 20:05:50 +0200 (IST) Received: from [192.168.16.203] ([192.168.16.203]) by us-gw1.zend.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 19 Nov 2009 10:18:47 -0800 Message-ID: <4B058C07.5070605@zend.com> Date: Thu, 19 Nov 2009 10:18:47 -0800 Organization: Zend Technologies User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 To: Jingcheng Zhang CC: internals@lists.php.net References: <4B045234.1010804@zend.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 19 Nov 2009 18:18:47.0442 (UTC) FILETIME=[BC7C0F20:01CA6944] Subject: Re: [PHP-DEV] The inconsistencies/flaws of PHP5's object model From: stas@zend.com (Stanislav Malyshev) Hi! > $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. That creates a myriad of problems due to the fact that if the class defines both __call and __get it is not clear what should happen. > 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 It might be, but in this particular language it isn't. PHP, unlike Javascript, is not a prototype-based language, and the classes are common between objects. > 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: It's kind of complicated to do because unlike the case with objects, a::g and c::g are different functions. So what happens if somebody tries to call a::g? You can do that with interfaces though. Also, the idea of having common base is usually that you expose the base class (a) as an API, and then implement it in certain ways which are hidden from the client, as he works with base type (a) only. However, in this case it obviously can not work, since a::g can't call anything, and for calling real name you have to know specific class name. > interface i { > static function f(); > } > class c implements i { > public static function f() { > echo 'c'; > } > } > function g(i $i) { > var_dump($i); > } > g('c'); > ?> > > 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". I'm not sure what you are trying to do here, but this code can not work - you ask for an object of type i and you pass string. I could guess you meant to ask for a name of a class that would implement interface i - but that is not supported by the language currently, as class is not an object in PHP. You would have to run your own code to do that, e.g. using is_subclass_of(). -- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com