Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60638 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56064 invoked from network); 21 May 2012 21:09:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 May 2012 21:09:22 -0000 Authentication-Results: pb1.pair.com header.from=tom@punkave.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tom@punkave.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain punkave.com designates 209.85.213.42 as permitted sender) X-PHP-List-Original-Sender: tom@punkave.com X-Host-Fingerprint: 209.85.213.42 mail-yw0-f42.google.com Received: from [209.85.213.42] ([209.85.213.42:37239] helo=mail-yw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 06/27-16352-00FAABF4 for ; Mon, 21 May 2012 17:09:21 -0400 Received: by yhfq11 with SMTP id q11so5567414yhf.29 for ; Mon, 21 May 2012 14:09:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:x-gm-message-state; bh=i76Dt898OXMJYeA6Zyev7LchmOJvs3+oni8BqvMF7tM=; b=N7gMw6iC75BXie57SZ5Gc97e2XHIGL+3WQ4jOHjq5ueP74yAj2TbvR0goWe3JGX/Hh Ewo4EcAB2UzO3FhlPmmxemC73XALTKZDXBEKRDVI6Gc53Tv2DLS6s4l1sIHCLjU/H0gr 3+7ap6wuLSl8MhoIoXxaV7ugg0GI8oyaDj1guXKZBozRekZoguIhYc0pxvUk+KvcoRza MRujEWDTGdZQ9gyArSIkBw/f/gPn9QjFCOCrjoG965En5fyVF2q5a4NFce215vehwGNa 9m8UVLSTs3w1DBkfRzEpnxtKZbX49Ah4295k4XhztA9Gbi3KfI6uoKQ1ZSyUuSuls8ZR ANFw== MIME-Version: 1.0 Received: by 10.236.76.133 with SMTP id b5mr25256766yhe.3.1337634557812; Mon, 21 May 2012 14:09:17 -0700 (PDT) Received: by 10.100.109.13 with HTTP; Mon, 21 May 2012 14:09:17 -0700 (PDT) In-Reply-To: References: <4FBA8FB0.80104@sugarcrm.com> Date: Mon, 21 May 2012 17:09:17 -0400 Message-ID: To: PHP Internals Content-Type: text/plain; charset=ISO-8859-1 X-Gm-Message-State: ALoCoQmowSLXl5V9EFV3nl6nw1BR0L0/DoXU1cEpkLJZlBctFoO7u4P0HFpS/7sz+9NOw3bz4d8s Subject: Re: [PHP-DEV] memory usage ouchy From: tom@punkave.com (Tom Boutell) Rasmus, isn't your concern about the impact of dynamic property support on developers who don't actually use it a nonissue in 5.4, where properties that aren't dynamic are stored as a flat array? On Mon, May 21, 2012 at 4:52 PM, Rasmus Schultz wrote: > Adding/removing properties at runtime is great if you want obscure, > unmaintainable code and don't think an IDE is useful. > > So to make my previous statement more precise, dynamic properties are > not widely used in respectable modern codebases, and is generally > something a reputable developer would frown upon. Yes, some codebases > (e.g. Drupal) rely on this extensively, but modern frameworks > generally do not - in fact, they often take measures to ensure that > exceptions are thrown if you try to access a property that has not > been formally defined. > > For that matter, most ORMs (a typical example of where dynamic > properties would come in handy) don't rely on dynamic properties > either - they rely on __get() and __set() and store the actual values > in a single property, as an array. So even for highly dynamic > components in modern frameworks, this is not a feature that is often > used. > > Drupal-development aside, and perhaps some XOOPS-development back in > the dark ages, I can't actually recall when I've used dynamic > properties. > > I suddenly realize why certain heavily-used classes in the Yii > framework have obscure property-names like $_m and $_p ... they're > trying to save memory. Not really logical that you should have to > compromise legible code in favor of saving memory. > > Makes me wonder if this issue could be addressed, killing two birds > with one stone. Since the dynamic aspect is an inconvenience to many > developers, and since it causes memory-overhead whether they make use > of this feature or not, how about introducing a non-dynamic > alternative base-class that actually throws if you access properties > that have not been defined? > > This wouldn't change the way PHP objects work by default, but would > lighten the memory-overhead in a lot of modern frameworks, and > possibly speed up property-access too, since you can have a flat > look-up table for class-properties; and could eliminate the need for > an "object" or "component" base-class in frameworks... > > > On Mon, May 21, 2012 at 2:55 PM, Stas Malyshev wrote: >> Hi! >> >>> How come it's necessary to store the property-names of every property >>> in every object? For properties that have been defined in classes, why >>> can't they be stored in a more efficient manner? (using lookup tables) >> >> No because you can add and remove properties freely at runtime. >> >>> I know the nature of PHP is dynamic, and I know that dynamic >>> properties would have to be stored in a key/value form internally... >>> but if you look at modern PHP software, dynamic properties is actually >>> something very few people use. >> >> This is not true. > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > -- Tom Boutell P'unk Avenue 215 755 1330 punkave.com window.punkave.com