Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:4787 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 95579 invoked by uid 1010); 10 Oct 2003 18:03:36 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 95554 invoked from network); 10 Oct 2003 18:03:36 -0000 Received: from unknown (HELO mx.thebrainroom.net) (65.200.24.98) by pb1.pair.com with SMTP; 10 Oct 2003 18:03:36 -0000 Received: by mx.thebrainroom.net (Postfix, from userid 517) id A7DEF1488089; Fri, 10 Oct 2003 11:02:01 -0700 (PDT) Received: from zaneeb.thebrainroom.net (zaneeb.thebrainroom.net [82.133.1.138]) by mx.thebrainroom.net (Postfix) with ESMTP id 978751488087; Fri, 10 Oct 2003 11:01:57 -0700 (PDT) Received: from titan (titan.thebrainroom.net [82.133.1.139]) by zaneeb.thebrainroom.net (8.11.6/8.11.6) with SMTP id h9AI3VK18276; Fri, 10 Oct 2003 19:03:31 +0100 Message-ID: <00bf01c38f58$d0480260$8b018552@titan> To: "Dan Cox" Cc: References: <3F865B5F.9090606@wep.net> <001601c38f1b$6e5132d0$8b018552@titan> <3F86F286.5010908@wep.net> Date: Fri, 10 Oct 2003 19:03:30 +0100 Organization: The Brain Room Ltd. MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.3790.0 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0 X-Spam-Status: No, hits=-0.8 required=5.0 tests=AWL,QUOTED_EMAIL_TEXT,REFERENCES version=2.55 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp) X-TBR-Filter: Virus scanned and defanged Subject: Re: [PHP-DEV] Accessing child constants from base class From: wez@thebrainroom.com ("Wez Furlong") > >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? It'll be slow no matter what you do, because you need to dynamically reference the constant value. You could also use the switch construct you already posted, or use the solution suggested by Ard; all of these are slow, particularly switch when used with a large number of string 'case's. You might actually find that the eval works out faster. If you're really thinking of writing high performance code in PHP, you shouldn't be writing code that has 100's of class definitions ;-) > 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 :) The engine only stores child->parent relationships, not child<->parent relationships. Think about it for a moment... can you do this kind of thing in compiled languages? Do you know why you can't? The reason is that the compiler has no way of knowing what classes are going to extend it at the time it compiles the base class. This is why I suggested that trying to dynamically access a constant (eg: compile time!) of a child class just seems wrong. --Wez.