Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123462 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id E12261A009C for ; Wed, 29 May 2024 20:58:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1717016380; bh=WoA1Bgv58lrLn2txwgSpLsGivgoZLY1hgga0F9i13uI=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=UHJ7LXsLEsNHj/0OlqxfH9kD2rxFVlZkhsDwZ7bnnsKdEdL1piQzZAGlUWgYb8zSn TvwdEiHDtDNwjs6rE2YGXyzfgIdWHkkTJyb+uZplEBxh6OUZgZW1WtB+sI8Ezxzv2S VQWaHf7kDzSw0khWveXeM2J7UnADp56u9GwmTk3gPX8j4fNvP4JPNr1uEZQ+Dj8g0Q BKXRyo4ImpERuDambbAJ2RVpTNIKfaplNVVt9kT45sQS5Gl5DyywuAkn8m0itxNXv4 XUsR/bLg11n2UUQ1B3OjsZUQDIjxjuP5YfgXp0JbGMnBxCcbkUudcKvkr0qOjSBGVZ bLGs3GgNmUS1g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0813218088A for ; Wed, 29 May 2024 20:59:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 29 May 2024 20:59:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1717016316; bh=WZw4q50o42HGJz1BLCCrtCpUtjpnn/TkCzz+8K5Hq+Q=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=ZIb9VMVJBdrmpnyHJTl/lMlszg+kZG04I1lRDl/XGR7gnEjl3Igrbql+xxt0wYzhs 7pQ775A0irHqI9E9xOpiUK11oDdfdYa+c+9A84zFMLx2BMi2wt+9lR9Yr8/BzXOK4r I/N+VdsN1xuDg88KvkMAZuiH+w3lq4HUnTkoulwbKjxhHHUGJnxKNsOm0UL1cjw56l FKaGvFznBjYM7xUdMBSyIBAiQE0rhByj0iEEjRauS40EI8OSmIH2tWxCNZsJOXfhWI XoGX7f+DAl5USSacoR62a2vT66ANzYJf3ElhlZOhPot+0WY6SZG30gU8umWtimaGME M91ICFOrsMqoA== Message-ID: Date: Wed, 29 May 2024 22:58:35 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Subject: Re: [PHP-DEV] [Discussion] Why can't I do "{$a::class}"? To: Robert Landers , Peter Stalman Cc: internals@lists.php.net References: Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi On 5/19/24 12:39, Robert Landers wrote: > In general, it would be nice to have some proper inline string > templating, like other languages (js, C#, etc). At least some way to > evaluate an expression and format. I'm thinking like in C#: > > $"Price: {price:C2}, Quantity: {quantity}, Discount: {discount:P1}, > Total after discount: {(price * quantity * (1 - discount)):N2}" > > Price is formatted using currency with 2 decimal places, discount is > formatted using percentage and one decimal, and N is a number format > with 2 decimals. While I can get behind allowing arbitrary expressions for ease of use, the formatting suffixes you suggested effectively replicate what `sprintf` already does for you, just with an "incompatible syntax". In fact for proper number and currency formatting you would likely need intl's MessageFormatter anyways, which already supports those kind of placeholders in a standardized fashion. Best regards Tim Düsterhus