Bug #81635 [Asn]: No example of complex interpolation syntax with filenames

From: Date: Thu, 18 Nov 2021 13:55:32 +0000
Subject: Bug #81635 [Asn]: No example of complex interpolation syntax with filenames
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237847@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81635&edit=1 ID: 81635 Updated by: cmb@php.net Reported by: shealavington at gmail dot com -Summary: \{ has special meaning in double-quoted strings +Summary: No example of complex interpolation syntax with filenames Status: Assigned Type: Bug Package: Scripting Engine problem Operating System: Windows 10 PHP Version: 8.0.12 Assigned To: cmb Block user comment: N Private report: N New Comment: Nah, there is nothing special about \{[1]: | As in single quoted strings, escaping any other character will | result in the backslash being printed too. Still, it makes sense to add an example, since backslashes in filenames and the given use-case are common on Windows. [1] <https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double> Previous Comments: ------------------------------------------------------------------------ [2021-11-18 13:37:43] cmb@php.net Thanks for the further clarification! > $newFoo = "(FILENAME='C:\folder\{$var}.txt')" You really should escape the backslashes in the first place; then you get the desired output: <https://3v4l.org/EKFq2>. > As you mentioned, \{ should not be escaping, but does. Indeed: <https://3v4l.org/lLZqF>. That needs to be fixed in the docs. ------------------------------------------------------------------------ [2021-11-18 11:56:21] shealavington at gmail dot com Indeed unclear, and most confusing. I'm working with a filesystem path within a larger string. I need to insert my variable after a backslash. For simplicity, we're using curly braces around all of our variables used within the string, and this situation doesn't allow us to do so. ``` $foo = 'bar'; $newFoo = "(FILENAME='C:\folder\{$var}.txt')" ``` outputs a string with a now invalid file path due to the parsing inconsistency. ``` (FILENAME='C:\folder\{bar}.txt') ``` As you mentioned, \{ should not be escaping, but does. Hopefully this issue can be looked into being fixed for later versions. ------------------------------------------------------------------------ [2021-11-18 11:40:49] cmb@php.net Yeah, this is actually unclear. "hello\{$foo}" This looks like complex string interpolation syntax, but is apparently parsed as simple string interpolation syntax, so $foo is being replaced with its value. So, I assume, that the backslash acts as escape for the open *and* the closing curly braces. ------------------------------------------------------------------------ [2021-11-18 11:31:29] shealavington at gmail dot com Notice how with this example I actually get one output with curlys and one without, which would suggest to me that there is a bug in the template parsing. ``` $foo = "bar"; var_dump("hello\{$foo}"); var_dump("hello\x{$foo}x"); ``` ------------------------------------------------------------------------ [2021-11-18 11:26:47] shealavington at gmail dot com I now see that \{ is not an escape sequence. However, that doesn't explain why the following ``` $foo = "bar"; var_dump("hello\{$foo}"); ``` outputs "hello\{bar}" instead of "hello\bar"... The curly braces should act as a variable wrap and should therefore be removed? Please do correct me if I'm mis-understanding here. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=81635 -- Edit this bug report at https://bugs.php.net/bug.php?id=81635&edit=1

« previous php.bugs (#237847) next »