Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62915 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 29472 invoked from network); 9 Sep 2012 08:22:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Sep 2012 08:22:28 -0000 Authentication-Results: pb1.pair.com smtp.mail=theanomaly.is@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=theanomaly.is@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: theanomaly.is@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:49419] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 15/82-06600-3C15C405 for ; Sun, 09 Sep 2012 04:22:27 -0400 Received: by lbbgp3 with SMTP id gp3so641776lbb.29 for ; Sun, 09 Sep 2012 01:22:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=NZr5mqvKAMPgyh/SkTJlr//1O7PTUjcHjwI6xwan+fE=; b=x+V8HxZuyxB4o3SWRvqPULkbIMBzxtv7KTBnQJA3HOokYgTwePIxFUNBNOxYL2qy+X 4zWNC56M80rupAS6dQ1kUMTxlHunbGkrWX79IAKyHSUvcPPmLABccT8plQXHH31h1vRi CGFoGXQvWu1akwpCdGIyAQ+JwuwdlKDdYdstIxgtKEINDu86CxU3YGtBkC9U8DAEnd+h MNDyX54b3ScktubOzKk+B3bM8zVJRMB0hEbCM8Lnv9dSCMwu1Z2ArR321gFRfAsE8ZfW KErdLQHb8aCWEsbZyub/ZM2Rp9mEkAAPXUxmTqaVl+7bRYMaHPbsga3fzV76bIgME4wZ FKhw== MIME-Version: 1.0 Received: by 10.152.112.233 with SMTP id it9mr9250728lab.40.1347178944038; Sun, 09 Sep 2012 01:22:24 -0700 (PDT) Received: by 10.112.12.178 with HTTP; Sun, 9 Sep 2012 01:22:23 -0700 (PDT) In-Reply-To: <1347177097.6077.82.camel@lat17.home.bof.de> References: <1347177097.6077.82.camel@lat17.home.bof.de> Date: Sun, 9 Sep 2012 04:22:23 -0400 Message-ID: To: Patrick Schaaf Cc: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] get_class_vars() returned information ORDER From: theanomaly.is@gmail.com (Sherif Ramadan) On Sun, Sep 9, 2012 at 3:51 AM, Patrick Schaaf wrote: > Hi, > > I'm curious whether the ORDER of the class properties returned by > get_class_vars(), is in some way guaranteed. I do not find mention of it > in the documentation. > The only real guarantee is that of how the class properties are stored in the hashtable. get_class_vars() is essentially just reading from a hashtable of class properties. > I'm especially interested in the order of static class variables > returned. > > Testing, using PHP 5.4.6, I find that there seems to be a stable order, > which suits my reasons for looking into this quite nicely. Here is what > I find: > > - static properties defined directly in the class itself come first, in > definition (source) order > - static properties defined directly in parent classes come next, in > definition order of their respective sources, and going up the class > tree. So grandparent properties come after parent properties > - static properties contributed by traits, all come AFTER the properties > from the class source itself, including all ancestors > - static properties contributed by a single trait come in definition > (source) order of that trait definition > - with static properties from several traits, those of the HIGHEST > class in the inheritance tree some first, and those from the class > under inspection come last. This is exactly the opposite order of > what happens with properties from the classes themselves. > > As it happens, the ordering I find for static properties contributed by > traits, is exactly what I was looking for. But is it guaranteed, or > could such a guarantee be made? > The order they're stored in the hashtable is as you've pointed out dependent on loading the definitions of the classes in the case of class variables. However, it's not a guarantee that get_class_vars() makes since it doesn't guarantee any order. It just so happens that it also doesn't try to intercede in whatever order the class variables are stored in in the hashtable. It's not like depending on the order of class variable definitions is something that crops up in any practical use cases that I've encountered. I wouldn't depend on order too heavily here. Anything were order is important to you should use an Array since that's what a PHP Array type guarantees (i.e. order). > best regards > Patrick > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >