Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115389 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 40558 invoked from network); 11 Jul 2021 18:39:52 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Jul 2021 18:39:52 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C752B1804C9 for ; Sun, 11 Jul 2021 12:02:55 -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,FREEMAIL_FROM,HTML_MESSAGE, 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-f173.google.com (mail-yb1-f173.google.com [209.85.219.173]) (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 12:02:55 -0700 (PDT) Received: by mail-yb1-f173.google.com with SMTP id k184so24676491ybf.12 for ; Sun, 11 Jul 2021 12:02:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Gt/KdKsFaNiWODsjdDXaJoego7s9j+nzjqLboHZSm6w=; b=VQPTEeD9iJ+bXd84zOYaf0aIRdt8ZoQJTcC/mTrIkg4kb9B4z1h7s7zMf4cUpj0VIo 0nv3w511u9o+T+S1EXUQ+IpYHDhzMeqq17mTU4UVLAGy1nVxfzMHpyUTUSwtRmGvwWJb LGDDfO2xGMFejb7bZRLmUJsMbohaGjv2c9GUaS8DdnLxb3EcvLElIhSt8sDIGD/nWGF3 B8nSU7GOWDdcqVRcu+oGS6f+KW9a16HrkCiPFRZCKzEphVPEFJLMY9KwoBDZSXuVvGVV L/qD0L2QqXZZ2FIYPXvA1vobsjOFnmrsVh8ShW9dR5B7u62tkd4KOjJFN1qYVoJIrt0a /Dcg== 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=Gt/KdKsFaNiWODsjdDXaJoego7s9j+nzjqLboHZSm6w=; b=nVElzrCEw6EcfN44tGqeAJDjhxmnIW+cf7h8U6xEkumbQmBzlZijLC0f/JjTclvzkn 0XceOwztLbhWmf8NrBngWxc5y2XPQcv1vkSfN+X8NIGpkIgnxaWrq8wFPsvMovSOh+NQ btk9yC8LhF7tPCQqpwH664qxizY/gQb9Uc/i3znGIrO6oZzrZltW9g+sJHVftTDxi+68 STQFwnYF7GbuLSd8woBs5IfDmlryQ0XoLhEIWYwy9OiyuKcYvlB/GHDZFEka2YICEJW4 r1EoUO3mTNc41PuCoGJvBOe1NZ9jCbrrW5zj6fvv8ZVJKiMt+ImlwHtDXO7RnYtZI2pb gPZQ== X-Gm-Message-State: AOAM532j2tNb4amRBpaEBOdcQ0p1GE0aQDAURXxb/CGlvBWDBNwgUZpy qNuuKO7jBmmFtVqY5+RslkO+5Ql+ST4I/yiVT1E= X-Google-Smtp-Source: ABdhPJx+y3/2fWBASpLXKX8Pz9zNG1i1kJDnqCIxvwK4Ed6ikqC3L8X3uJOX6W329CK0JPYqB7p2r3Hew+66nBNVeuI= X-Received: by 2002:a25:b701:: with SMTP id t1mr57245942ybj.517.1626030173681; Sun, 11 Jul 2021 12:02:53 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 11 Jul 2021 16:02:42 -0300 Message-ID: To: Max Semenik Cc: Internals Content-Type: multipart/alternative; boundary="000000000000e57e9105c6dda684" Subject: Re: [PHP-DEV] Type casting syntax From: david.proweb@gmail.com (David Rodrigues) --000000000000e57e9105c6dda684 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I really like the casting syntax, but I think it is difficult to be approved, at first, because there is already a "clearer" method for doing something like that. Which for me, particularly, does not invalidate an alternative. My suggestion is to create a magic method like __cast(AllowedTypes $in): self. Eg. __cast(string|int $in): BigNumber. Where AllowedTypes are the classes allowed to be casted from (or "mixed"). So: $bn =3D (BigNumber) '123'; $date =3D (Carbon) $date; $timestamp =3D (Carbon) (int) $date; I also wanted it to be possible to use a nullable cast, but the idea didn't go forward (even though there were no alternatives). :( Atenciosamente, David Rodrigues Em s=C3=A1b., 10 de jul. de 2021 =C3=A0s 06:10, Max Semenik escreveu: > I've been thinking about extending PHP's cast syntax to user-defined type= s, > e.g. not only (int)$foo but also (MyClass)$foo. Currently, a T_STRING in > parentheses is always treated as a constant - would it be acceptable to > hijack this syntax when used in unary operation context, i.e. "(" T_STRIN= G > ")" expr? If not, any other alternatives? > > -- > Best regards, > Max Semenik > --000000000000e57e9105c6dda684--