Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93601 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70037 invoked from network); 27 May 2016 09:18:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 May 2016 09:18:41 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.53 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.53 mail-wm0-f53.google.com Received: from [74.125.82.53] ([74.125.82.53:36219] helo=mail-wm0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7B/55-37127-0F018475 for ; Fri, 27 May 2016 05:18:40 -0400 Received: by mail-wm0-f53.google.com with SMTP id n129so263192172wmn.1 for ; Fri, 27 May 2016 02:18:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=zrjj3EbnFEcpKf/8DkNDrcj2/XHMupnvYSFkSqMPDL8=; b=nYr0NiRbUl9B3QfJkVTwsERu0tfEOgSI6SxDpyEYl+SAiYEfK16eaQIXjAm5lLazlY 5tOfFyuVJG4HCwT01rbwNtWxbvvBmNuGkN7GqTJk6FuY2cCVojeG7vw0kNXm91xRjJ0/ 0DcVCO3UGcGxAuqvT1SRA/LbzuNNzQdJMFaN3Op7AS/pNHdogC/C29+O2wz1ViBxAu/C 5cSE3xGkAnQWNiF23UUItHU5+3tHYThBmn17pp3gO7u7mscouhLhqpEruH3qlAUjxslz 3H2GXFj7UXlHlC67G1m/Zy1zma7706xzGkPYpdNWBCR7esHzI5ANov3d9zD7hNObfSzm CQhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=zrjj3EbnFEcpKf/8DkNDrcj2/XHMupnvYSFkSqMPDL8=; b=H+85ypILjuetV8HLYwiLc5zuviVdc3WSzp0g37v4+6G30O4005fNqp2nZ+7d3TTC+X fWjxTnHJR81poD9cbmNky63WavEEI0Z/ZiK4YU5olISbXUz+gbKbSyupJadXQlLOD5pe 04XdnkkGbTWxZc9ZrsA5WWqh/+nVPtLg7ZlULQBNiYU8hmXv52E2i3lNvx7Q2TymGFG7 Rc0PXj2sEAX+PwaE0Qejl7cmECNa0ynsA6Q3Igyzd7zGLnlHR4rTmj7v4V6QqKeQE81n hknru/HPL1u9Sr32Gr77NgmdaKYFq3z/9SxTzVJ16aWr9plIJFc9lYOZ4uJH0FBU01tO NutA== X-Gm-Message-State: ALyK8tLBRc8+QIXORP0xCU/vLJMjsfoF/FtZHf6qHd23lhRBuFkio1lRdZzHgC7j54UgiQ== X-Received: by 10.194.117.3 with SMTP id ka3mr13663289wjb.38.1464340717467; Fri, 27 May 2016 02:18:37 -0700 (PDT) Received: from [192.168.0.98] ([93.188.182.58]) by smtp.gmail.com with ESMTPSA id dd7sm18417830wjb.22.2016.05.27.02.18.36 for (version=TLSv1/SSLv3 cipher=OTHER); Fri, 27 May 2016 02:18:36 -0700 (PDT) To: internals@lists.php.net References: <20160525215208.034FC1A801B3@dd1730.kasserver.com> <5fd54aa0-4fdf-c1e7-eae8-765aa89c8498@fleshgrinder.com> <08963b03-8394-6d62-4e5b-393f3fcb5647@fleshgrinder.com> <9e9db70d-d72d-d93e-0c81-18c2aa228618@gmail.com> <409002d8-b5e3-5990-7358-246adc7e3cab@fleshgrinder.com> <57474A08.80807@lsces.co.uk> <6f7403b6-bf22-a12b-dfb2-43fe82983e7d@fleshgrinder.com> <57474F9C.6080104@lsces.co.uk> <1733cfce-001b-1079-e929-88f7dde0f2dd@gmail.com> <57475F27.3090306@lsces.co.uk> <50f5d1c9-d24f-1afe-4c34-70aafd981524@fleshgrinder.com> <5747697A.7000906@lsces.co.uk> <37377d3b-827a-4cfd-580b-e33862084ab6@gmail.com> <5747F02A.2010808@lsces.co.uk> Message-ID: <426da65f-bc9a-93ed-ce16-0fefe8b9eb43@gmail.com> Date: Fri, 27 May 2016 10:16:49 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC][Vote] Typed Properties From: rowan.collins@gmail.com (Rowan Collins) On 27/05/2016 09:35, Tony Marston wrote: > "Lester Caine" wrote in message news:5747F02A.2010808@lsces.co.uk... >> >> On 26/05/16 22:36, Rowan Collins wrote: >>>> So every time I update the current tree because the client has selected >>>> a different initial root I have to destroy perhaps 30 person objects >>>> and >>>> rebuild the whole lot again from scratch? >>> >>> In a word, yes: if you have a different set of data, use a different set >>> of objects to hold it. >>> >>> Objects are not memory slots to be re-filled, they represent a specific >>> instance of a thing. > > I disagree completely. In a database system there is no rule that says > an object can only hold data from a single row otherwise Martin Fowler, > the author of PoEE, would not have patterns that hold data from several > rows. When I instantiate one of my table classes it is a valid but empty > object. There are two actions I can perform - inject data from the > client via the $_POST array, or tell it to retrieve data from the > database. This may involve just a single row, or multiple rows. When > reading from the database it may even result in zero rows. That sounds like an object that represents the database table as an entity, that's fine. What does it contain - how is the row data represented? If it's just an array of arrays, then none of this discussion is relevant; if it's an array of model objects, then those objects must have properties, and those properties can be given type annotations under this proposal. My comment was in reaction to Lester expressing surprise at destroying and re-creating objects when new data is fetched. To be clear, I'm talking about this: // Clear old data $this->data = []; // Re-populate from new DB result foreach ( $db_resultset as $row ) { $this->data[] = new SomeModel($row); } The most useful typehints are inside the SomeModel class, not the table-level wrapper. This is true even if they're just dumb structs, and all the behaviour is at the table level, because it presumably has basically one field: array $data. The alternative implied by Lester's comment seemed to be to somehow re-use the entries in the data array by calling a magic "reset" method, then populating them with new data. That's what I meant by "slots". If I create a Person object representing "Lester Caine", it makes absolutely no sense to go out of my way to recycle it and use it to represent "Tony Marston"; that's a new value of the same type, so a new instance of the same class. Regards, -- Rowan Collins [IMSoP]