[PHP-BUG] Req #70087 [NEW]: Better string interpolation

[email protected] ("mario dot dweller at seznam dot cz")
Newsgroups php.standards
Message-ID <[email protected]>
From:             mario dot dweller at seznam dot cz
Operating system: 
PHP version:      7.0.0beta1
Package:          PHP Language Specification
Bug Type:         Feature/Change Request
Bug description:Better string interpolation

Description:
------------
There is a support for variable interpolation in strings like
`$string = "$a/$b $c";`
or
`$string = "{$a}/{$b} {$c}";`

But it is not usable for functions.
`$string = "Length: {strlen($a)}";`

I guess that's why many programmers prefer using sprintf instead because
it is more readable than concatenation using dots. I personally use
sprintf almost everywhere because the code looks more consistent then.

Since there are many cool new features in PHP7, why not to add this
basic one?
I guess it would need a special syntax because of BC, or not?
But there are currently two ways to achieve the same thing:

`$string = "Hello {$a}";`
`$string = "Hello ${a}";`

The second one looks unnaturally, most prefer the first way. For example
it could be forbidden in favor of this:

`$string = "Length is ${strlen(a)}";`



-- 
Edit bug report at https://bugs.php.net/bug.php?id=70087&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=70087&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=70087&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=70087&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=70087&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=70087&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=70087&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=70087&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=70087&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=70087&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=70087&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=70087&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=70087&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=70087&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70087&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=70087&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=70087&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=70087&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70087&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=70087&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=70087&r=mysqlcfg
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.