Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:31961 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20570 invoked by uid 1010); 29 Aug 2007 15:01:30 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 20555 invoked from network); 29 Aug 2007 15:01:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Aug 2007 15:01:30 -0000 Authentication-Results: pb1.pair.com smtp.mail=rewbs.soal@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rewbs.soal@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.132.241 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: rewbs.soal@gmail.com X-Host-Fingerprint: 209.85.132.241 an-out-0708.google.com Received: from [209.85.132.241] ([209.85.132.241:30491] helo=an-out-0708.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 34/60-17634-94A85D64 for ; Wed, 29 Aug 2007 11:01:29 -0400 Received: by an-out-0708.google.com with SMTP id c18so56501anc for ; Wed, 29 Aug 2007 08:01:27 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=Mn3awaLf2feweu3xXdygrQg4k8OR+OIwsDQX0zmiRxG0/dW36r2ae0VRPRMf9Os/tTbu3SGYRZgzDChHeU4e9M3WIEsP+aT8bv8c3W4MZRurcLgvR6bgmM+wV3SI6uxrWIIVZx/9eCwgiKo3mxr0OKcWpN0wFVIU6vy9y1i91Pk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=B+7XZVqgbtOVCCkEqAXEdld73za8I5HIO0GGgF7FgkYfq7UzwAUplwy1Zftr59hguYrjiQxwJz6Kz7Zq3RAA2o938g2FAKI5a/O9S5yrn/n8YNzwz0nQvxH2swHVUccSNg4Fu1Vjt2yM+Q1QIYWA178qSZ2cQbKKFgS5lVRssws= Received: by 10.100.13.12 with SMTP id 12mr603112anm.1188399253951; Wed, 29 Aug 2007 07:54:13 -0700 (PDT) Received: by 10.65.211.9 with HTTP; Wed, 29 Aug 2007 07:54:13 -0700 (PDT) Message-ID: <5a8807d10708290754i1cbbb772hd34592060f3ad97@mail.gmail.com> Date: Wed, 29 Aug 2007 15:54:13 +0100 Reply-To: robin@soal.org To: internals@lists.php.net MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Subject: self:: or parent:: in an inherited class property declaration From: rewbs.soal@gmail.com ("Robin Fernandes") Hi all, There has been some discussion on this list about late static binding and the 'self' & 'parent' keywords. I'm looking to understand the meaning of self:: and parent:: when used in the declaration of an inherited class property or constant. Based on discussions here and on comments to bugs like http://bugs.php.net/bug.php?id=30934, my understanding is that self:: should be bound statically at compile time. Therefore, in the example below, I would naively assume that self:: would always refer to class A. However, this is not the case. It seems that at compile time, the engine flags class properties/constants that depend on class constants. They are then subject to a one-off re-evaluation at execution time. The flagging is done by setting the zval 'type' field to IS_CONSTANT, IS_CONSTANT_ARRAY or IS_CONSTANT_INDEX. The re-evaluation is done in zend_update_class_constants(). When self:: is involved, the result of this re-evaluation is not always intuitive imho, and appears to contradict the idea that self:: is bound at compile time. See this test case for an illustration: http://pastebin.com/f1d93fb2e To summarize the behaviour exhibited by that test case: 1. An inherited static property's value depends on the order in which classes are touched at execution time. The meaning of 'self' is fixed, but depends on the scope in which zend_update_class_constants() is first executed. Removing line 15 changes the outcome of the test. 2. An inherited instance property's value depends on the instantiated class. When accessing the inherited property through an instance of A, 'self' is taken to mean A. When accessing it through an instance of B, 'self' is taken to mean 'B'. Presumably, this is because the property is propagated to the subclass before its default value is evaluated. 3. Similarly to 2, an inherited constant's value depends on how it is accessed. When accessing A::INHERITED_CONST, 'self' is taken to mean A; when accessing B::INHERITED_CONST, 'self' is taken to mean B. Is this as expected? I would argue that at least point 1 is a bug, but would appreciate opinions before I investigate further. (The exact same issues apply when using parent::. See this testcase: http://pastebin.com/f249a0e8c ) Regards, Robin