note 58353 deleted from language.types.string by cmb

From: Date: Sun, 04 Aug 2019 09:11:32 +0000
Subject: note 58353 deleted from language.types.string by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-211798@lists.php.net to get a copy of this message
Note Submitter: DELETETHIS dot php at dfackrell dot mailshell dot com ---- Just some quick observations on variable interpolation: Because PHP looks for {? to start a complex variable expression in a double-quoted string, you can call object methods, but not class methods or unbound functions. This works: <?php class a { function b() { return "World"; } } $c = new a; echo "Hello {$c->b()}.\n" ?> While this does not: <?php function b() { return "World"; } echo "Hello {b()}\n"; ?> Also, it appears that you can almost without limitation perform other processing within the argument list, but not outside it. For example: <? $true = true; define("HW", "Hello World"); echo "{$true && HW}"; ?> gives: Parse error: parse error, unexpected T_BOOLEAN_AND, expecting '}' in - on line 3 There may still be some way to kludge the syntax to allow constants and unbound function calls inside a double-quoted string, but it isn't readily apparent to me at the moment, and I'm not sure I'd prefer the workaround over breaking out of the string at this point.

« previous php.notes (#211798) next »