On Thu, Mar 17, 2016 at 12:23 AM, Phil Sturgeon <pjsturg...@gmail.com> wrote:
> > Yet, your argument was about avoiding is_null() calls within application > > logic and you'd gain nothing if you end up having to write ! empty() > > instead. :) > > I'd rather have a NULL to tell me that I have nothing instead of a > > supposedly initialized but otherwise invalid value. > > > > Cheers, > > Andrey. > > Not sure what you're saying there Andrey. > > > That's fine. Type checking doesn't say that a value is correct or > meaningful; it just enforces the shape of the data. > > Larry > > Solid points! Exactly that. A type relevant default of 0 is not > definitively invalid, it's up to application logic to work that out. 0 > is totally valid as an integer. > > I do quite like the idea of type relevant defaults being provided, so > 0, [], "", etc, just like Go. > > The only trouble I see there is: what sane default is given for > `public Foo $foo;`? Instantiate the class? Erf. > I guess I'm not being verbose enough then ... I'm not really good at that. Given this class as an example: abstract class Foo { public int $bar; } We're discussing whether the $bar property should be allowed to have a NULL value after instantiation, right? Larry's point being that it can't be NULL, so that we don't have to do is_null() checks throughout the code. And I understand that. However: 1. You'd only need to do the is_null()/isset() calls if you're not sure whether the property was populated with a meaningful value (i.e. if you constructor doesn't populate it) 2. A meaningful value is one that is valid for the application logic, because that same logic defines its ... meaning 3. If you absolutely forbid typed properties to hold NULL values, you'd force users to resort to using int(0), float(0.0), string('') as the defaults for properties that cannot be populated at instantiation time for whatever reason (and you know people WILL do anything as long as it hides an error message) I'm not saying that these defaults are definitely invalid (and as far as typing goes - sure, the type is correct), but they will be *meaningless in a lot of cases*. So now you still have to check if the property was really populated or not, only using a function different than is_null(). I'd say that's inventing a new problem in order to solve the old one. We don't want that, do we? :) Cheers, Andrey.