Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103204 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 50493 invoked from network); 20 Sep 2018 18:33:44 -0000 Received: from unknown (HELO mail-pg1-f181.google.com) (209.85.215.181) by pb1.pair.com with SMTP; 20 Sep 2018 18:33:44 -0000 Received: by mail-pg1-f181.google.com with SMTP id b129-v6so4523706pga.13 for ; Thu, 20 Sep 2018 07:40:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mindplay-dk.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MmMiddEUBe7kyeLYLc9X27/Af5LxU0/eYMovSDzAkhY=; b=yRVHldRtUy2SYk+hyFAO9JZGbBWKrjRAoyUJbj9mr0uqrzTq/umCYg8qXt5g0Zu1kd mj6dw868VtehMmCX2XTbtUXd0Uty0eIm0xJSo1/jRWtngzOUKlIO9W4yPy7AwqhiNpFP ceGzTIGRghjI79cuBjXWliUZ2P+m+DAMU/TxZM43ii4SGrXdcBxeAvNraLkIxX9glTGa ebmW0vVA8+k+xac8mrFpDixSrr6U5uIEN6deCsPQDRIuY79SZRufbQYDxXSNsI8oGaj6 0ExB99AnOuQ2wyzjTiULGL3Pvt6n+XG0vSM7SjmgAZcSa8WGVttNd4oxkmiF2DDjezVB qSUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MmMiddEUBe7kyeLYLc9X27/Af5LxU0/eYMovSDzAkhY=; b=bmONi16vvS+V9plBOwq4zIn/Fows3qik3+qrRR6YFcPgTeZCjDK8mZaGjlgg+rRvJR aCFCHBqGvCbO+To3x4bkGieD3JYgmLccmzGkZCZLm9Z9sTnrBb3CQ3kYnEl+UfG7LjC8 EdKHQp7tdt3pBtTieUFR7FeUNNO64cNzxXH/GkOps9gF5i6MUCGSmBGt7kP84n+ZGvfd 3Yljbr9Zu5LrFT9vf8rZMCUkvbM2w2q76pbYLgntHrdsqbHS7F2RUGVujqS3Mb4D/lu0 24gH2OPvZbDr2gtSHZis7DG1wxhD4DIDe4ZDdlzDEQS3zQGAmx3rmimgufiSdosUiWlB gfCg== X-Gm-Message-State: APzg51C5Qiw+PVGGueE5LLtdiMvpz7Uz/4ycHQYmGNSW4akfwhHCM3gK K6cxg7ROqIfR+IMABHLblSZ2IJJ3VpOd1XijsCJvrw== X-Google-Smtp-Source: ANB0VdZuvbWrCNVuOvnwegY1ZwyXtM8QN6T+hQQTZ6GbL5gVhuYV5oJ0NjCWmkn3FiZHqxySHHtpnCXmhztJ+LS0GkE= X-Received: by 2002:a62:2b50:: with SMTP id r77-v6mr41452316pfr.51.1537454421706; Thu, 20 Sep 2018 07:40:21 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 20 Sep 2018 16:40:10 +0200 Message-ID: To: levim Cc: rowan.collins@gmail.com, PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] [VOTE] Typed properties v2 From: rasmus@mindplay.dk (Rasmus Schultz) On Wed, Sep 19, 2018 at 10:04 PM Levi Morrison wrote: > I think this code should be allowed: > > class User { > public int $id; > public string $preferred_name; > public string $username; > } This code is broken - by making the properties non-nullable, you're literally saying "these properties will be initialized", then proceeding to not initialize them. That's just incomplete code. Note that we're talking about two different things here - I was talking about bypassing declared constructors for technical reasons. You're talking about omitting constructors from the declaration - but all classes have a constructor. Not declaring it just implies an empty constructor. You can even invoke it using reflection. For your use-case, assuming you insist on writing bad code, is more accurate like this: class User { public ?int $id; public ?string $preferred_name; public ?string $username; } These properties are valid without a constructor. You can safely infer them as null, rather than as "uninitialized". Non-nullable properties aren't valid without initialization. Not in any language I've ever heard of. Maybe PHP has to be the first to prove every other language right? We have enough half-baked features and inconsistencies as it is. We'll regret this forever. Like how Javascript developers regret having null and undefined on a daily basis. Uninitialized is the new null - it's the PHP equivalent of undefined in Javascript. Please no.