Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115394 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 79826 invoked from network); 12 Jul 2021 06:40:41 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Jul 2021 06:40:41 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 505D81804C4 for ; Mon, 12 Jul 2021 00:03:52 -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-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (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 ; Mon, 12 Jul 2021 00:03:51 -0700 (PDT) Received: by mail-lj1-f181.google.com with SMTP id a6so22521738ljq.3 for ; Mon, 12 Jul 2021 00:03:51 -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=fOmbA0bx3Y5/kIkAE6mQfZFmDgAd8oO3yjyR4lHQ2Wk=; b=l2XB5YX34c/YQ3MQ8KGiqgoQ1Hpk2/aEyoGKMIrMcz74SuiXATBKLhHu6s0T9GH4pL ZiRtXwNsKSF/HCNkUhZNGkplxsNMCL2J6sZIosckzlKNZbSn5tB8bwZ9eLcnzcXzCPxv tyYVUnvmekjK0xS5bdsvlvsaz/bFszn1MJM7hlxwAjZUA1N7EaNdKoAS/6ekzzVz7Ddu w+XEQets/5+uQyVoJ2TeWt6BeIomkf2CkWwMgBGgfBvPy15Ooapa7GbVfBXfCBBVuXUM gPVIpsm/6bKzTZbHc6OILZGFXU7r/ZkXQHRSrxJYxL3E3AE/m5FhTTjyHG3XS3LGce2M lcSA== 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=fOmbA0bx3Y5/kIkAE6mQfZFmDgAd8oO3yjyR4lHQ2Wk=; b=Jfhxzs3deb6XbFrxzT+WQAxr9mFPI0q3+YprFTcT2IjMYzal5bY6onM/slUZIxb9w5 K1qu6Cr3LbwRhbh6/dopdQ6t1cuos8sOcrJdvc/xgMMv7qlbKYx8ZorXFmeP3i8iDFZw 87TE3tunzMn4qUwtIjUkqBuZUeSCvjWhlQESWHA6niJLfl8aUYqE4TCaS1oh5zRqsaoh gD7O+apprm8KnbdWJrP1IVQH0u9dAEc8sgNAp6LsU+aKzaJC0w8mQNuuKtIjb3qdUExu 4b18aP8SMsek9cAQliIFJj9CkJkT55E+FTNeICBaoyUB6X/27d3Trjr099y5FKjaMr3a xqRw== X-Gm-Message-State: AOAM5335vEA55sLLSgbMb2IUB97LCMgNg7QYxbsvutIlisXh95VmWfuO srsgby2U0Rw7/UFu0kR/boNV2Cg+fbb/EmpD4sg= X-Google-Smtp-Source: ABdhPJwG3XylvjJX2K7Q21rWQYKzQFyw0GguKNgJlaxUtdQU4Dr1Vv2tUMXFkD2I+NllSAUyldwzceTXwbTRD98i8OQ= X-Received: by 2002:a2e:8813:: with SMTP id x19mr5512339ljh.272.1626073430100; Mon, 12 Jul 2021 00:03:50 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 12 Jul 2021 09:03:34 +0200 Message-ID: To: Max Semenik Cc: Internals Content-Type: multipart/alternative; boundary="0000000000002e0f3e05c6e7b93e" Subject: Re: [PHP-DEV] Type casting syntax From: nikita.ppv@gmail.com (Nikita Popov) --0000000000002e0f3e05c6e7b93e Content-Type: text/plain; charset="UTF-8" On Sat, Jul 10, 2021 at 11:10 AM Max Semenik wrote: > I've been thinking about extending PHP's cast syntax to user-defined types, > 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_STRING > ")" expr? If not, any other alternatives? > To answer your question without commenting on the wider discussion: No, it's not possible to use this syntax. C-style cast syntax is hopelessly ambiguous -- there's a reason why modern languages always pick a different syntax for type casts. To give a simple example, (MyClass) (CastArg) is already valid PHP syntax and performs a call to the function stored in constant MyClass, with the argument CastArg. Regards, Nikita --0000000000002e0f3e05c6e7b93e--