Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123365 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 EF8381A009C for ; Sun, 19 May 2024 10:39:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1716115239; bh=6GLjVBIbJ6POr/rymEUJMkxz2M3aPQK81+c2yFJw1B0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=KnqtezlHYZykgpITS4kS/8HspOu4jcRDVthyg8GKDauFOkHxpgu4Ynll63wyMP0Qo /roANWZX/+H/QCG9NS4WcQ5xTlUSA2qI9jJnMVnobq8o8v91L7gPBXFdvqERg1dAMn bM958QaEK3OORE831NcY/Nt4+p/f8wWK33UF3mu+1vYR5WfX7yp5RuejCfKSVs1+Uh s5G1Msz1RDVe0dUNA9E/pLPDTnrmjQL/usT1SRhjmPZr9hQPD68cH46OqtkIjRtZm2 Z09uZqJv0c0UULUL95VkckSxGMSxb7ppSQoWkmP2UEcWNgrIQIDed+BVSQWAnjNbW+ 3LS4k8Asl8rAA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 90E5A1805A0 for ; Sun, 19 May 2024 10:40:38 +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,FREEMAIL_FROM, RCVD_IN_MSPIKE_H2,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 mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 19 May 2024 10:40:38 +0000 (UTC) Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-51f40b5e059so2606535e87.0 for ; Sun, 19 May 2024 03:39:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716115182; x=1716719982; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=iFdYF/st96AIIZTtT9BIps2UGsmqrePQ4eRreFGzMzM=; b=PGGqU8u024O6nxYouGzFp7+uKKGEdmogj7wit5PIjY6zr/6zhE7yMvlU8u1WMhOKx8 5J39OKTQS7WMhC9gRBPkqKDMu+DrKQBW8bZnbJzFXPbCOae01hxyEKXpV6bR3mbAyGWd r8rWoLl6cBydo0i9PMJ+QfXEqja2U8BzdqBUQkg11d0Et3MKVKjmdlecQez0NJXY7jiE 3TdylsCSCsR0Mf58eLxPUONMZ6eik3XczN33Qv6m9Q2j6deSwGfK9tyXFPuJcmz12S90 MlpCwe50h9pBICYv2CeV1np2h6HhWMlkW25R4eubLC50OODlvh70RTVVT2ez6oylYtd7 9iVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716115182; x=1716719982; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iFdYF/st96AIIZTtT9BIps2UGsmqrePQ4eRreFGzMzM=; b=T8i8P3VGbXHOQm6R6EeYbWhChSqUfP61E59o48RMz5e9x4UX+2t6QGqDA5c7Gwlbgp iTpsQ+gDn/SbLSEZe42sSjRSn7XMiwpchNwBhAp0ewrr04VMZ2w21QvGuEXzqXrn0o8V t38dwkZcODHMZBSvPky8F93t40BGt1bj5E+IsnWHxovBSi++kyVe0DI07Yo7i2NC0JBB eB1SvvfJzUCjCb/kwTIs6+Y0KpjpRmckDVSnwzMWfZwMioA83xkL9k8smIMjhrkfq47o xc/rfVwN4Ki/l9Vvw0tsb7vco6mHH80GU/+QbG9JX+1Nyyt4WDmu1PLlEzIkiE4hCUlG f+HQ== X-Gm-Message-State: AOJu0Yze7yd9BfJYf+oOuoSVOFP6VIHnlkRWo4BBdxJE9JESsiAzZFUe zNQCwj8L0sQkN13MY7+4LGru6CQWhnZBt6yUeNSm61QvvauGLBtAr+GGpv3d89oLbX0MpoEW2NG 0pC1XDjX3foJ3XKA1w8XWULWk6ak= X-Google-Smtp-Source: AGHT+IFWtnpCSPajXiOh2ePHNPj9VC3vkolj2B4z0xxzojM+KFzc9OLN6No58lKjXBQ/EC4NH4Tu6owNNG5dExxRlAo= X-Received: by 2002:a05:6512:1083:b0:523:41ba:a297 with SMTP id 2adb3069b0e04-52341baa3b9mr14173389e87.5.1716115181842; Sun, 19 May 2024 03:39:41 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 19 May 2024 12:39:29 +0200 Message-ID: Subject: Re: [PHP-DEV] [Discussion] Why can't I do "{$a::class}"? To: Peter Stalman Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: landers.robert@gmail.com (Robert Landers) On Sun, May 19, 2024 at 10:33=E2=80=AFAM Peter Stalman = wrote: > > Hi Internals, > > Obviously we can't use constants or functions directly in strings using v= ariable parsing, I assume because it lacks the easily detectable $. > > However, we _can_ use methods because the object variable has the $, whic= h I assume is the reason methods work and functions don't. > > I feel like it's something that _could_ have been added when dynamic acce= ss of static members support was added in 5.3.0, but maybe it was overlooke= d or decided against? Consider: > > ``` > > $a =3D new A(); > > echo " {A::$static_property} \n"; // doesn't work (unless $static_propert= y is a variable) > echo " {$a::$static_property} \n"; // works > > echo " {A::static_method()} \n"; // doesn't work (just text) > echo " {$a::static_method()} \n"; // works > > echo " {A::constant} \n"; // doesn't work > echo " {$a::constant} \n"; // doesn't work either, but why? > > ?> > ``` > > > Also, as a side note, why does this hack below work? It seems like somet= hing that would use `eval()`, but doesn't. Take a look: > > https://3v4l.org/aPCSD > > I found it at the bottom of the manual entry for Strings[1]. Not somethi= ng I would use, but it's interesting to see. > > Thanks, > Peter > > [1]: https://www.php.net/manual/en/language.types.string.php#91628 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. Robert Landers Software Engineer Utrecht NL