Re: [RFC][Vote] Typed Properties

From: Date: Fri, 27 May 2016 09:53:05 +0000
Subject: Re: [RFC][Vote] Typed Properties
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20  Groups: php.internals 
Request: Send a blank email to internals+get-93604@lists.php.net to get a copy of this message
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 = []; > // 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. Probably the only difference here is that '$row' in my result set is not a dumb structure. It has type information, field lengths and potentially 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. -- Lester Caine - G8HFL ----------------------------- Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.uk

« previous php.internals (#93604) next »