Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:4786 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80578 invoked by uid 1010); 10 Oct 2003 17:53:14 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 80541 invoked from network); 10 Oct 2003 17:53:14 -0000 Received: from unknown (HELO spike.wep.net) (66.171.16.54) by pb1.pair.com with SMTP; 10 Oct 2003 17:53:14 -0000 Received: from wep.net (internal [192.168.1.1]) by spike.wep.net (8.12.8/8.12.8) with ESMTP id h9AHtIHZ022472; Fri, 10 Oct 2003 13:55:18 -0400 Message-ID: <3F86F286.5010908@wep.net> Date: Fri, 10 Oct 2003 13:55:18 -0400 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20030929 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Wez Furlong CC: internals@lists.php.net References: <3F865B5F.9090606@wep.net> <001601c38f1b$6e5132d0$8b018552@titan> In-Reply-To: <001601c38f1b$6e5132d0$8b018552@titan> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Accessing child constants from base class From: dan@wep.net (Dan Cox) Hi Wez- Wez Furlong wrote: >This sounds like you're doing something wrong (no offense!). > >You want to access a *constant* of a descendant class, when >your ancestor doesn't even know if it exists. >Well, that sounds more than a little odd (backwards even). > > > >Why not just use a property with a known name, and set the >value of that property in you descendant class constructor? > > > Yes, this is how I'm doing things now. It just seems like I shouldn't be forced to always have to use parent::__construct(_MY_CONSTANT_) >Performance wise, its not going to make much difference, >because no matter what you are doing, to dynamically resolve >the value of a constant will involve hash lookups. > >The other alternative, and this is the official POV of the >Zend guys IIRC, is that you can use eval() to look up >the value: > >$node = $doc->createElement(eval(get_class($this) . "::ElementName")); > > > Yes. Normally, at least with most other programming languages, using eval() is a major performance hit (as much as 10x slower), so it shouldn't be used unless there is absolutely no other way. Maybe this isn't the case with PHP? >If you think about it, what exactly does child:: refer to anyway? >A child class of the current object? But which one? What if >the child doesn't have the constant? What if there are interfaces >involved? > > > A deriving class of the current *instance* .. so childInstance:: then :) Perhaps you could use interfaces to enforce children having the needed constants. >The engine doesn't know about descendant classes either (the >inheritance tree works in the other direction), and it shouldn't >have to second-guess what your code is doing - its much clearer to >explicitly write code like that eval above. > >Hope that helps! > >--Wez. > > > I suppose. It just seems odd that a class can talk to it(self::) and it's parent:: but not its child:: even though the child:: instance started the conversation in the first place :) Dan Cox