Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:59915 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 7617 invoked from network); 13 Apr 2012 21:27:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Apr 2012 21:27:38 -0000 Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.170 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.216.170 mail-qc0-f170.google.com Received: from [209.85.216.170] ([209.85.216.170:43993] helo=mail-qc0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D5/16-11739-74A988F4 for ; Fri, 13 Apr 2012 17:27:35 -0400 Received: by qcmt36 with SMTP id t36so2434975qcm.29 for ; Fri, 13 Apr 2012 14:27:32 -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=5EhxM5oVcMVFQ7NpFjn2Edobm3wKce6ceeoWcMaLYGw=; b=YA1+BumIXa525jLJ5Gri9eoGTlGqyYS6fPIZWHkyKuprxLIZe4HnSZplod+MPdcnTL 7QwXw6kIT4/LIFEakp7z/C9Fb3aFDO4vS+cpYcbP2idEvZg9Vo40En1DtBf5yZ5rqFOB 0lNp6LSY77EQFv7vXLx9e7LyCLt+xt+bsGKQxzBvx3opkHYAo+A+clvn/web5GKarNm7 ZuMfa8k0HVDkDOxWAmP9CAeJknWPGIG3qzS7AgNIVAN5JPR9KY0bfvjmlIAef3wInMWM U44VTDxDjW0nSDbaoUHK9CiQmFA870jHbt6WmIo3VLO1rJracvSQOVEb8QFXI5bg/uWD 0/hg== MIME-Version: 1.0 Received: by 10.229.75.139 with SMTP id y11mr1359148qcj.69.1334352452902; Fri, 13 Apr 2012 14:27:32 -0700 (PDT) Received: by 10.229.42.4 with HTTP; Fri, 13 Apr 2012 14:27:32 -0700 (PDT) In-Reply-To: <4F888746.4050705@sugarcrm.com> References: <01ed01cd19aa$58810e80$09832b80$@alliantinternet.com> <4F888746.4050705@sugarcrm.com> Date: Fri, 13 Apr 2012 17:27:32 -0400 Message-ID: To: Stas Malyshev Cc: Dmitri Snytkine , PHP Internals Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] Ability to assign new object to a class property. From: ircmaxell@gmail.com (Anthony Ferrara) Stas, > Because the engine doesn't run code when parsing class definitions so > defaults should be constants (otherwise would also create a lot of > trouble for bytecode caching as object are not cacheable). Just throwing this out there, but that code wouldn't be run on parse. It would be "queued" to run prior to the constructor on instantiation. So then, we should be able to execute that code inside of _object_and_properties_init... Then, all you'd need to do is add a single field to _zend_property_info to indicate it should be a class instantiation. From there, you'd want a flag on zend_class_entry to indicate if it has any dynamic properties. So the work flow would be that in _object_and_properties_init, when it copies the hash table, check the flag on the zce. If true, iterate over the properties to check for instantiation, and if so, do it. This would (in theory) be able to support almost any type of dynamic code in the property declaration, as long as it doesn't reference `$this` (which would still be undefined at that point). So you could do: protected $foo = "bar" . BAZ; protected $fiz = new Biz(new Baz, array(123)); Just a thought... Anthony On Fri, Apr 13, 2012 at 4:06 PM, Stas Malyshev wrote: > Hi! > >> Why can't we create a new object and assign it to property like this? > > Because the engine doesn't run code when parsing class definitions so > defaults should be constants (otherwise would also create a lot of > trouble for bytecode caching as object are not cacheable). > > Use ctor for complex initializations. > > -- > Stanislav Malyshev, Software Architect > SugarCRM: http://www.sugarcrm.com/ > (408)454-6900 ext. 227 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >