Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93606 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80503 invoked from network); 27 May 2016 10:33:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 May 2016 10:33:57 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@fleshgrinder.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=php@fleshgrinder.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fleshgrinder.com from 212.232.25.164 cause and error) X-PHP-List-Original-Sender: php@fleshgrinder.com X-Host-Fingerprint: 212.232.25.164 mx208.easyname.com Received: from [212.232.25.164] ([212.232.25.164:35139] helo=mx208.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F6/57-37127-39228475 for ; Fri, 27 May 2016 06:33:56 -0400 Received: from cable-81-173-133-15.netcologne.de ([81.173.133.15] helo=[192.168.178.20]) by mx.easyname.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1b6F5U-0005dZ-TF; Fri, 27 May 2016 10:33:53 +0000 Reply-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> <426da65f-bc9a-93ed-ce16-0fefe8b9eb43@gmail.com> <57481901.1070102@lsces.co.uk> To: Lester Caine , internals@lists.php.net Message-ID: <3381028e-b243-0e0e-9632-bf3ee6f16e70@fleshgrinder.com> Date: Fri, 27 May 2016 12:33:34 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 In-Reply-To: <57481901.1070102@lsces.co.uk> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="1xs4OTwNJhuVVRF989IobECoLTxU1PC4i" X-ACL-Warn: X-DNSBL-BARRACUDACENTRAL Subject: Re: [PHP-DEV] [RFC][Vote] Typed Properties From: php@fleshgrinder.com (Fleshgrinder) --1xs4OTwNJhuVVRF989IobECoLTxU1PC4i Content-Type: multipart/mixed; boundary="ncqAJrtj31Lqu5h9FibFiAj7R0rsBnHwV" From: Fleshgrinder Reply-To: internals@lists.php.net To: Lester Caine , internals@lists.php.net Message-ID: <3381028e-b243-0e0e-9632-bf3ee6f16e70@fleshgrinder.com> Subject: Re: [PHP-DEV] [RFC][Vote] Typed Properties 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> <426da65f-bc9a-93ed-ce16-0fefe8b9eb43@gmail.com> <57481901.1070102@lsces.co.uk> In-Reply-To: <57481901.1070102@lsces.co.uk> --ncqAJrtj31Lqu5h9FibFiAj7R0rsBnHwV Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 5/27/2016 11:53 AM, Lester Caine wrote: > On 27/05/16 10:16, Rowan Collins wrote: >> 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 =3D []; >> // Re-populate from new DB result >> foreach ( $db_resultset as $row ) { >> $this->data[] =3D 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, a= nd >> all the behaviour is at the table level, because it presumably has >> basically one field: array $data. >=20 > Probably the only difference here is that '$row' in my result set is no= t > a dumb structure. It has type information, field lengths and potentiall= y > even value constraints. So my table level wrapper can potentially have > the same typehints that you are then adding to SomeModel. All the > properties of SomeModel already exist and if typed properties are > working correctly in PHP $row can simply be accessed directly. This is > why in my book all of the debate about 'attributes' and everything else= > is so tied up in the definition of making a simple variable a much more= > flexible generic object. >=20 The type hints belong to SomeModel because you want to insert the data into SomeModel and not into your repository (Table). class Person { public int $id; public DateTimeImmutable $created; public DateTimeImmutable $changed; public string $name; public DateTimeImmutable $birth; public ?DateTimeImmutable $marriage; public ?DateTimeImmutable $death; public int $number_of_siblings =3D 0; } class SomeModels { public function findAll() { foreach ($db->select('SELECT * FROM `SomeModel`') as $row) { $some_model =3D new SomeModel; $some_model->id =3D $row['id']; $some_model->created =3D new DateTimeImmutable($row['created']); $some_model->changed =3D new DateTimeImmutable($row['changed']); $some_model->name =3D $row['name']; $some_model->birth =3D new DateTimeImmutable($row['birth']); if (isset($row['marriage'])) { $some_model->marriage =3D new DateTimeImmutable($row['marriage'= ]); } if (isset($row['death'])) { $some_model->death =3D new DateTimeImmutable($row['death']); } $some_model->number_of_siblings =3D $row['number_of_siblings']; yield $some_model; } } } The Person object is however still behaviorless and anemic, throwing type hints at public properties does not change that fact. --=20 Richard "Fleshgrinder" Fussenegger --ncqAJrtj31Lqu5h9FibFiAj7R0rsBnHwV-- --1xs4OTwNJhuVVRF989IobECoLTxU1PC4i Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJXSCKDAAoJEOKkKcqFPVVrnSoP/0MdqsjphYn7oYmxExm2OIZl eTKMTFRgEw4Gy2Y7mTxoDftzU0Grvv/NuSVx47VsE6DUW1siQMD6WHnTWRs1ubDy frCXCgM01hQeIOCZMilxuBIiLIsWEFe3uso941kZQZtUQbKjA3BQOgAs7Zf4IiMP OwaQ/BFe+WvCxyg3ctIwcSpU00auNzeC60h0kxeC2emwPOMyQr1zMtWpB08T7maQ IKebEzYLVjlFlUELL9Z0w/KQmkUuP+57bd1KwuKzn95q5GRIhA0gbdh1YYPfBHna +DXZ1Qt9eWq/i276Q6bG4vmOl5nO8V9G6zNAYB5yYH1WHVczKQbACweRXCnETTZ+ cTls3gQxZtJgwSVm2yvjOGj/wCs6mfNYqU4pfNB+smj9rrS8oNdwcY6sWNRGqipN omaBib4Al55W54GV2mNgORHvmrAYQ7atzsWfJVjkeRicSV0YfIlqWBFtgVGG0gJl WDlIN/VU0z7/D7qKk7Xxsr6CZM9m6iLoDJko4RO3ay5h/Wsg/7m1tWYDGHjeKkxG eW3FL80NcjA7zlJuBNa34xwhJ2JxNx+xMKhD/Sao4DNlo87L7Q57Ve3ga7qihuwj SSFiuVStvvv8T4Ee1nQzj6l1zg11WXeBr0FIhAe9K355k8e/t0PB3SHIhL+5bJnC gzkfI3zUYTME7Ii5efsl =zO9S -----END PGP SIGNATURE----- --1xs4OTwNJhuVVRF989IobECoLTxU1PC4i--