Bug #75999 [NEW]: Use functions inside complex (curly) syntax

From: Date: Fri, 23 Feb 2018 07:58:09 +0000
Subject: Bug #75999 [NEW]: Use functions inside complex (curly) syntax
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-214076@lists.php.net to get a copy of this message
From: damianglinkowski at gmail dot com Operating system: PHP version: 7.2.2 Package: Strings related Bug Type: Bug Bug description:Use functions inside complex (curly) syntax Description: ------------ I want to use function inside complex (curly) syntax, for example: $name = ' Some name '; echo "Your name is {trim($name)}."; I expected to see: Your name is Some name. but I've got: Your name is {trim( Some name )}. So I've added $ before {: echo "Your name is ${trim($name)}"; and now I've got PHP Notice: Undefined variable: Some name It's Ok, there isn't that variable but why php call the method trim? Test script: --------------- function foo() { return 'normal_foo'; } class Bar { public function foo() { return 'class_foo'; } } $bar = new Bar; echo foo(), "\n"; echo $bar->foo(), "\n\n"; echo "foo()\n"; echo "$bar->foo()\n\n"; // Bug? echo "{foo()}\n"; echo "{$bar->foo()}\n\n"; // END Bug? // Here php calls function, why? echo "${foo()}\n"; Expected result: ---------------- normal_foo class_foo foo() PHP Notice: Undefined property: Bar::$foo in /home/d0niek/test.php on line 21 () normal_foo class_foo PHP Notice: Undefined variable: normal_foo in /home/d0niek/test.php on line 26 Actual result: -------------- normal_foo class_foo foo() PHP Notice: Undefined property: Bar::$foo in /home/d0niek/test.php on line 21 () {foo()} class_foo PHP Notice: Undefined variable: normal_foo in /home/d0niek/test.php on line 26 -- Edit bug report at https://bugs.php.net/bug.php?id=75999&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75999&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75999&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75999&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=75999&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=75999&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=75999&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=75999&r=needscript Try newer version: https://bugs.php.net/fix.php?id=75999&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=75999&r=support Expected behavior: https://bugs.php.net/fix.php?id=75999&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=75999&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=75999&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=75999&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75999&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=75999&r=dst IIS Stability: https://bugs.php.net/fix.php?id=75999&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=75999&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=75999&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=75999&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=75999&r=mysqlcfg

« previous php.bugs (#214076) next »