Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91722 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59872 invoked from network); 16 Mar 2016 22:54:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Mar 2016 22:54:53 -0000 Authentication-Results: pb1.pair.com smtp.mail=narf@devilix.net; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=narf@devilix.net; sender-id=pass Received-SPF: pass (pb1.pair.com: domain devilix.net designates 209.85.218.44 as permitted sender) X-PHP-List-Original-Sender: narf@devilix.net X-Host-Fingerprint: 209.85.218.44 mail-oi0-f44.google.com Received: from [209.85.218.44] ([209.85.218.44:34407] helo=mail-oi0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9B/C1-48430-C34E9E65 for ; Wed, 16 Mar 2016 17:54:53 -0500 Received: by mail-oi0-f44.google.com with SMTP id m82so50359534oif.1 for ; Wed, 16 Mar 2016 15:54:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=devilix.net; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=QMR7TmtEnyeZ0C4Ze+ZLhg3zIU7eI1uoZb5dpFgy4JA=; b=Kphc1/H9vZR7pBCzWz7AD7J+3SR65GaJ7eKq2mFcwNUMzFcE4A2JIqsfjAA2FAwJeW XjdSED7IKhphPtTQ7OXpzCnYNH+5IKBg2Ah9aA/VfeclNMyNYpnuO8Kodq2whMUqfoB1 Ih9Kd4TgF333IsJfAFAFqVAVgL6JNKRvwDiu4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=QMR7TmtEnyeZ0C4Ze+ZLhg3zIU7eI1uoZb5dpFgy4JA=; b=HWdKnPI58Hz6Razf/xpWhq/PHY/qjS+jAuX99DYPKuTMtr/F1bPu/AqB4Kvwha4Nls nfjz9CFOQBGVkW4KK4M+WL4w8Rb5x3+9qn1EcLTCNbqDWmjF7XocHaN6VwvUqZxy1Ef3 auozJoYR0LYp9kMo9hOr+CJut8l6gwGhhnrt4/3wF19PYtJOEXI/X4uoVxuEceFCwHwp dqagMHUefwi8Yx9tMGmyW45cGuGQupoxIHBelM1k0ymdy9+pOhJICSN+kBKNZ1ICbfln 1OtnmKW7fZZzokXS6JHqZEYUUIgsIZsENaqC34fxhL5Fybv+miZcDq+/D25P8qP7nfoO OiWQ== X-Gm-Message-State: AD7BkJL+Jslr3D6hnPY5TEB6gti3tp/GKx9HbVDj9rSPc6pvGks2TDHjELPnlsXdaHKu9e5PqZfFgcWhoSoaVQ== MIME-Version: 1.0 X-Received: by 10.202.104.204 with SMTP id o73mr3988891oik.18.1458168890038; Wed, 16 Mar 2016 15:54:50 -0700 (PDT) Received: by 10.202.175.74 with HTTP; Wed, 16 Mar 2016 15:54:49 -0700 (PDT) In-Reply-To: References: <56E9AAF1.7070200@garfieldtech.com> <56E9D787.8070705@garfieldtech.com> Date: Thu, 17 Mar 2016 00:54:49 +0200 Message-ID: To: Phil Sturgeon Cc: Larry Garfield , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a114087aab6af0e052e326687 Subject: Re: [PHP-DEV] [RFC Discussion] Typed Properties From: narf@devilix.net (Andrey Andreev) --001a114087aab6af0e052e326687 Content-Type: text/plain; charset=UTF-8 On Thu, Mar 17, 2016 at 12:23 AM, Phil Sturgeon 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. --001a114087aab6af0e052e326687--