Re: [RFC][Vote] Typed Properties
| From: | Rowan Collins | Date: | Fri, 27 May 2016 17:43:31 +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-93613@lists.php.net to get a copy of this message | ||
On 27 May 2016 13:34:17 GMT+01:00, Lester Caine <lester@lsces.co.uk> wrote:
>Hence the 'in an ideal world'! It is perhaps worth making clear that a
>'typed property' element IS simply a holder for the pointer to the real
>element while the untyped properties are the element themselves?
In database terms, a property - typehinted or not, scalar, whatever - is like a column. On a
particular instance (= row) each property will have some particular value.
Consider how "father" would be modelled as a foreign key in the DB. If you don't know
the father, you would insert a null, not reference a special row representing The NullFather. And if
you discovered the father was incorrect, you would update the row to point at a new record, not
change the name on the old father record - it is not the name that was incorrect, only the
relationship.
So in OO you do the same: if you don't know the father, you store a null in that field. If you
want to change the father, you point at a new object, you don't go in and edit the existing
one.
$this->father = $newFather;
There's no "empty object" here, no need to "reset" the object which was
incorrectly assigned to the father property, just a new association representing the corrected
information.
--
Rowan Collins
[IMSoP]