Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:44017 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90620 invoked from network); 17 May 2009 07:54:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 May 2009 07:54:11 -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 74.125.46.29 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: 74.125.46.29 yw-out-2324.google.com Received: from [74.125.46.29] ([74.125.46.29:39272] helo=yw-out-2324.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 25/2D-07963-2A2CF0A4 for ; Sun, 17 May 2009 03:54:10 -0400 Received: by yw-out-2324.google.com with SMTP id 3so1473454ywj.83 for ; Sun, 17 May 2009 00:54:08 -0700 (PDT) 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:content-type; bh=sA8BuOT37G89byYCYokxD0Gl1pV2/c07gCpo5iULCJY=; b=dz852lXye6Tp7CHhB2Cy6kbMHZ/0FmxjB/TMRArEanihUTnWqiYJy2gOjLguxCBt3a L7+5QMP6rrlYDj0WHXCZ7xOADjWMXxiddX019rBUcFQXAP4XthkTy6CbkSaA4oXaF0QE zjxmlCxleV6bBWqpqCoo/t+GSwSX4c9LSpmkA= 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 :content-type; b=xu1zZ1n/gqMt0Ey0eUXHu2GkUCNYAd+sGgMWoTJ6dC4t/wW3nASZdi2xCDqexPwD8F eDYxvaadz70tLRa4h9jr/sZcBgGRr5xuy5CMkA6HJKRnYzePz19gLfCVumWcIQXlq10e m5NEjJan1b7Jmf8GMP5YMd+bR/o3qKIJTayPY= MIME-Version: 1.0 Received: by 10.151.122.9 with SMTP id z9mr9873950ybm.196.1242546848036; Sun, 17 May 2009 00:54:08 -0700 (PDT) In-Reply-To: References: Date: Sun, 17 May 2009 15:54:08 +0800 Message-ID: To: php-dev Content-Type: multipart/alternative; boundary=001e680f1ac47e78f6046a16fb0e Subject: Re: Suggestion on static field inheritance From: diogin@gmail.com (Jingcheng Zhang) --001e680f1ac47e78f6046a16fb0e Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Nobody is interested in this topic? Another confusing feature is "static function", which is allowed in interface, but not allowed in abstract class, any explanation or reason for this? Thanks :-) 2009/5/16 Jingcheng Zhang > Hello all, > > Maybe I have not found its detailed description on PHP's official manual, > but PHP does allow static field inheritance. However there is a little > difference between dynamic field inheritance and static field inheritance, > as the following codes shows: > > class static_a { > public static function change($name) { > self::$name = $name; > } > public static $name = 'a'; > } > class static_c extends static_a {} > class static_d extends static_a {} > > echo static_a::$name; // a > static_c::change('c'); > echo static_a::$name; // c > static_d::change('d'); > echo static_a::$name; // d > > > class dynamic_a { > public function change($name) { > $this->name = $name; > } > public $name = 'a'; > } > class dynamic_c extends dynamic_a {} > class dynamic_d extends dynamic_a {} > > $a = new dynamic_a(); > $c = new dynamic_c(); > $d = new dynamic_d(); > echo $a->name; // a > $c->change('c'); > echo $a->name; // a > $d->change('d'); > echo $a->name; // a > ?> > > The result of static inheritance test can be meaningful on some > way(especially on class-based programming perspective), but when considering > the static class as "object" in prototype-based programming(which I doubt is > some people's favourite who comes from prototype-based OOP community), this > result can be confusing. On JavaScript, this example can be: > > > > This looks more meaningful. So my suggestion is, could PHP's static > inheritance rule follow the dynamic inheritance rule ( $this on dynamic, or > prototype delegation on JavaScript) ? > Thanks :-) > > -- > Best regards, > Jingcheng Zhang > P.R.China > -- Best regards, Jingcheng Zhang Room 304, Dormitory 26 of Yuquan Campus, Zhejiang University P.R.China --001e680f1ac47e78f6046a16fb0e--