Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115390 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 53552 invoked from network); 11 Jul 2021 22:08:04 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Jul 2021 22:08:04 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BD2B81804C4 for ; Sun, 11 Jul 2021 15:31:09 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f170.google.com (mail-yb1-f170.google.com [209.85.219.170]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 11 Jul 2021 15:31:08 -0700 (PDT) Received: by mail-yb1-f170.google.com with SMTP id g19so25454279ybe.11 for ; Sun, 11 Jul 2021 15:31:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=datadoghq.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6n8IV7Gtj6SEVkdhQSnaAsDjeipT9C7YcOCTFVnpOKg=; b=PhTcPA1K/u4s6ZA4lMQb4ukV/v7ZsQS9OwJCtAJs3faWxG3BWirb5YJ2GoUWRbalwW tZGxinrc7lMpKTz2mH+InUEItVo6u7F37DF0aQZOx6Bm8Ilf0V9Dpvo+hlETW4dcCcol BhH/umOnnugTfuTT6DPOMyLXkpvbU12MxUJFY= 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=6n8IV7Gtj6SEVkdhQSnaAsDjeipT9C7YcOCTFVnpOKg=; b=nUTxLFw7BLbpiJz5PD8SOcs/oK3aWK1odsPGvgx7qYnlosKIcksoUfeVD3/Z1DYYqw p2GgfyPdIXrsd5NJQliLl0kaKIh1ypqkYvWiJtzPhH9rtPwvzcWyOzHyF0hPsRPvgSA+ /cJXwlTbT5SKs1S3mMOlMusNnfBRefl6hFMqQWteO2xEdKAOwBkjOlgNs6EIrwZFumJx tnz/LgCWABjZ4WW0gDvUfTK/vL9ZdspjMDD9zqh2E4VBxSm446jglmZitIA0UKaSY3rk K6ctru5/ynslYr7RbQNwc4/wa/bCa3XKgKVEC4hXqcGV0zxtVTpPOCT45Yd+eK7gjX/F wxZA== X-Gm-Message-State: AOAM530RTuMoo9xqDtFGZ2n1KG+TcqGARl6EtE50hbghJABwlouYrP0o UTc9Cz23y5y1HNCLuqclrD4CVIzDwCz0HQFT301DMw== X-Google-Smtp-Source: ABdhPJyNshQo385q8sR76+/RL31XAaRG30EYtf/thB/itYAopGdB5tzSekYOTxWkkafcoM8qzjWSjYoNmZMM1OoZm0k= X-Received: by 2002:a25:e803:: with SMTP id k3mr57752379ybd.268.1626042668283; Sun, 11 Jul 2021 15:31:08 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Reply-To: Levi Morrison Date: Sun, 11 Jul 2021 16:30:57 -0600 Message-ID: To: David Rodrigues Cc: Max Semenik , Internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Type casting syntax From: internals@lists.php.net ("Levi Morrison via internals") I like Rust's From and TryFrom traits, which allow types to define conversions into or from other types. The From trait always succeeds, and TryFrom can fail. However, it's not a "cast" -- the user calls an `into`/`try_into` or `from`/`try_from` methods. I would be supportive of defining official ways to convert types from one to another, not necessarily casts, though. I think these qualities are important: 1. Would have failable and non-failable variants. It's nice to know that a particular conversion cannot or can fail. 2. It should be amenable to static analysis. Tools should be able to warn about missing paths for handling failable conversions, or that conversion from A to B is possible but A to C is not. I'm not sure how to technically achieve this for PHP. I don't think any casting proposal I've seen meets these characteristics, so I would personally vote no on them.