Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:30072 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52591 invoked by uid 1010); 5 Jun 2007 15:58:00 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 52576 invoked from network); 5 Jun 2007 15:57:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Jun 2007 15:57:59 -0000 Authentication-Results: pb1.pair.com smtp.mail=colder@php.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=colder@php.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain php.net from 213.239.212.54 cause and error) X-PHP-List-Original-Sender: colder@php.net X-Host-Fingerprint: 213.239.212.54 dns1.omne-serveurs.net Linux 2.4/2.6 Received: from [213.239.212.54] ([213.239.212.54:51982] helo=dns1.omne-serveurs.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DB/2C-11953-40885664 for ; Tue, 05 Jun 2007 11:57:57 -0400 Received: (qmail 649 invoked from network); 5 Jun 2007 15:57:51 -0000 Received: from 80.218.249.160 by dns1 (envelope-from , uid 1004) with qmail-scanner-1.23 (clamdscan: 0.82. spamassassin: 3.0.1. perlscan: 1.32. Clear:RC:1(80.218.249.160):. Processed in 0.07831 secs); 05 Jun 2007 15:57:51 -0000 Received: from 80-218-249-160.dclient.hispeed.ch (HELO ?10.0.0.1?) (80.218.249.160) by dns1.omne-serveurs.net with (DHE-RSA-AES256-SHA encrypted) SMTP; 5 Jun 2007 15:57:51 -0000 Message-ID: <466587FF.5040808@php.net> Date: Tue, 05 Jun 2007 17:57:51 +0200 User-Agent: Thunderbird 1.5.0.7 (X11/20060909) MIME-Version: 1.0 To: Jochem Maas CC: Bart de Boer , internals@lists.php.net, Ken Stanley References: <56275.216.230.84.67.1180484964.squirrel@www.l-i-e.com> <465D9040.6030001@iamjochem.com> <43689.216.230.84.67.1180643866.squirrel@www.l-i-e.com> <465FC76B.6030208@mediawave.nl> <4660A44F.6060802@mediawave.nl> <46657E94.1030900@iamjochem.com> In-Reply-To: <46657E94.1030900@iamjochem.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] late static binding (please break BC?) From: colder@php.net (Etienne Kneuss) Jochem Maas wrote: > Bart de Boer wrote: > >> Ken Stanley wrote: >> >> > > ... > > >> That's not right. Accessing the child class would only be possible from >> within an instantiated object. Unlike parent::, you will never be able >> to use static:: in a purely static context. Imagine there are multiple >> child classes which all inherit from the same base class. If there's no >> instance, PHP won't be able to know which child class to target with >> child::, static:: or whateverkeyword:: since it can be any one of those >> child classes. >> > > huh??? the 'child' class would refer to the class that was actually named > when then call to the method was made (thats what late static binding means, > does it not?): > > class Data { > static function getTableName() { > throw new Exception('WTF'); > } > > static function findRange() { > $t = child::getTableName(); > } > } > > class Prod { > static function getTableName() { > return 'PRODS'; > } > } > > Data::findRange(); // child = Data class > Prod::findRange(); // child = Prod class > > if you require a class instance in order to use 'child' then > the whole point is moot - because you can already do > > $child = get_class($this); > > inside the relevant function (assuming the function is not declared static, > and why would you declare it as such if your requiring an instance to use 'child'?). > > maybe 'child' should be called 'callee' or even 'lsb' (that would make people > hit the docs for sure :-)). alternatively maybe 'this' could be used as the LSB keyword: > > this::foo(); > > the samentics for determining what class is referred to with 'this::' is akin to > that used for determining what class is referred with '$this->', no? > > MAYBE php6 should do late static binding for 'self', akin to other OO oriented > scripting langs .. and just live with BC. I seriously wonder whether much code would > break ... given that 'self' is not currently late binding how often would people have actually > overwritten static methods ion child classes that are being called via the 'self' syntax > in [parent] classes? > Hello, In an instance, fetching the class and running call_user_func is quite overkill, hopefully the dynamic access of class method/member/const will get accepted/commited. There is no reason (implementation wise) to restrict LSB to static callstacks only. By the way, "child" is not a good term either as it won't always represent the child, i.e. the class itself. Changing the behavior of "self" seems like a bad idea, it will make every script using "self" (many) rely on the call stack, which will among other things break BC and slow things down. -- Etienne Kneuss http://www.colder.ch colder@php.net Men never do evil so completely and cheerfully as when they do it from a religious conviction. -- Pascal