Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106851 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 94129 invoked from network); 4 Sep 2019 14:20:49 -0000 Received: from unknown (HELO mail-pf1-f195.google.com) (209.85.210.195) by pb1.pair.com with SMTP; 4 Sep 2019 14:20:49 -0000 Received: by mail-pf1-f195.google.com with SMTP id y22so7458727pfr.3 for ; Wed, 04 Sep 2019 04:54:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=basereality-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MO0mg0qE1xPVAqf7TkedvIYaHYJ0g/c+dVfi36F3lqY=; b=r8lahYyHez4IQWYRWD0+FYfwzDJxqiLnME1OpPx1IoBYiQ6qyQDqtxnBFsrgnlWFWJ R2bj+joe1q79Omm4NOgrbV3SVLGO2x1ALZIc77TRAvJhBDgV8Pb8jaj0vFhHyoY2Zvda vBZq0929Yn7mxOueUaYmnMPMjj2fUzd7WQ3pL+75iT6tPhtWimeM0GdmfWa7hYC+IE6T 0B4KbNsQ9744hI9MMtA6Z9JP8CU0fUw2LV9myaJTEjuuRHvXi//t2M96dllrtrt1bxdL WZLDDTd+kYAYZ6Hsjy23fLVXMcRpZjti6R1Rs8/jrOJtfdcWNhn2ix9+txBQNS+qGtzq KOLA== 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=MO0mg0qE1xPVAqf7TkedvIYaHYJ0g/c+dVfi36F3lqY=; b=jxhBrNh2UAOHm7mrTJZ5fCylbXRIubwvys70aUOAWDe0oSTbyfMdAXP/xI/WOhO6jB HS2M0NcniFcPRjzMdVdR9IBO/PXAeVarPfgOnxg+wSBCcpst0P1E7qcuRqHuxx+I1ZKb 9iP0BYqgIZz6Wnc6a9IvNoH1krsKBJ9XqTWxicUQxXbt1Y+P107/QQxXRX47m+g92sVf q3cphjQCnA7Qdf5LT9wQJ6XpjYMiv6xm3gSGIzKCG4uru6I3fJJfAnxGjjbA0XpypDF5 LDqCXICKaqropJeLJPm3fs3vrAQfN5t2c2GNXEK4vito2my4+OE7J3+egGUgUYCKqprJ jN0g== X-Gm-Message-State: APjAAAUAE7OuMrGEWFy75OvjE8QDAuHgNBPvPWaqzJPhtrchtTJnxKr0 ln0fQEOc124p2oC+CIAOatM4dtEK3F0zQguOEN3sEA== X-Google-Smtp-Source: APXvYqw/CmdTc/YHfm3K+vY6m9rJjmpNTueAHQrUBWoMfBHedgbDcYYNUQuoQRloWtuJGl9uLY0tjFRHNH2AwjIbilY= X-Received: by 2002:a62:8745:: with SMTP id i66mr44994908pfe.259.1567598082513; Wed, 04 Sep 2019 04:54:42 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 4 Sep 2019 12:54:31 +0100 Message-ID: To: Nicolas Grekas , arnold.adaniels.nl@gmail.com Cc: Nikita Popov , PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] Union Types v2 From: Danack@basereality.com (Dan Ackroyd) On Wed, 4 Sep 2019 at 10:59, Nicolas Grekas wrote: > we use "@return $this" quite often. On the implementation side, I'd > suggest enforcing this at compile time only (enforce all return points are > explicit, and written as "return $this" That's doing a deeper level of thing than a type system normal does. It's enforcing the internal behaviour of a function, rather than just defining the type of the parameter that is returned. > if we were to use "?int" instead, the engine would force the > community to add "return null;" That sounds like a bug to me. The fact that null is returned by any function that lacks an explicit return value, is well-defined, and one of the most underrated aspects of PHP imo. Arnold Daniels wrote: > Instead of using `__toString` as type maybe it's better to introduce > a `Stringable` interface, Although casting things to string is probably the most common use case, if you're going to think about an RFC along those lines, covering all of the scalars would probably be a good idea, as that would allow people to use specific types for values, that can then be passed easily to functions that expect a scalar. function setRetryLimit(int $maxRetries) {...} class ImageUploadRetryLimit extends int {...} function processImage(ImageUploadRetryLimit $iurl, ....) { ... setRetryLimit($iurl); ... } That type* of stuff is completely possible currently in PHP, it's just that it's a bit painful to both write and read. cheers Dan Ack *intended