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 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php