Re: [RFC Discussion] Typed Properties

From: Date: Sat, 19 Mar 2016 12:17:39 +0000
Subject: Re: [RFC Discussion] Typed Properties
References: 1 2 3 4 5 6 7 8 9  Groups: php.internals 
Request: Send a blank email to internals+get-91774@lists.php.net to get a copy of this message
On 3/19/2016 12:23 PM, Lester Caine wrote: > On 19/03/16 11:02, Fleshgrinder wrote: >>>> Properties need the ability to be void even after construction and it is >>>>>> up to the object to keep track and ensure state. Nullability is imho not >>>>>> necessary at all. So we are all in line here. >>>> >>>> If the record I am working with identifies elements are incorrectly >>>> matched, then making a value 'void' is the correct action. We would just >>>> NULL that identifier and fire off a delete to the linked record in the >>>> database. Otherwise we have to create additional logic to handle that. >>>> >> And *void* would translate to *unset($record->property)* and not to >> *$record->property = null*. This works with the current implementation >> and any *isset($record->property)* works too. As you can see, >> nullability was not required. :) > > I did not say what we have now is actually right ... NULL state is > simply a mess :) > > I need '$record->propertyX = null' because the property is part of the > data model. Unsetting propertyX so it does not exist means I have to > recreate it if I want to add it again, BUT if I am reading a new record > from the database I need a variable to put the propertyX into even if > that element of the result array is 'NULL'. > > Going back to 'basics', I have an array of fields ( and using ADOdb > rather than PDO I have accurate data on what each field is! ). > Initializing the object view of that record I scan each field value and > validate the data, or skip it if the field is NULL. Do I need a > propertyX if it has no value - in my book yes - so that when building > the template to display the data I can include that this does not exist. > Could I use 'isset' instead - no - because THAT state says leave out the > field from the data display altogether. Could I create some arbitrary > default value that is 'not set' ... yes, but that is not how the years > of code base has been built! NULL is 'value not set' not 'this variable > does not exist' > You are mixing to things like I did. If you never unset and never assign then the value of the property is *null* or as I defined to avoid confusion *void*. All fine. The question was, should this result in an error and the general consensus here is /no/. The thingy with *unset* would be during runtime for whatever dubious reasons. -- Richard "Fleshgrinder" Fussenegger

Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
« previous php.internals (#91774) next »