|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2021-10-07 06:56 UTC] dean at omnivisiontechnology dot com
Description: ------------ --- From manual page: https://php.net/language.operators.string --- In general, PHP doesn't specify the order of evaluation for operators. However, order of evaluation for the string concatenation operator specifically, does always seem to be left then right. If this can indeed be guaranteed, then it should be specified in the documentation, because it enables the very common coding idiom: $string = 'something'.($complicatedSubstring = 'something else').'more stuff'.$complicatedSubstring; Test script: --------------- $s = '[Very bad!]' $x = 'bar '.($s = 'foo').' bar bar '.$s.' bar'; Expected result: ---------------- $x should be 'bar foo bar bar foo bar'. It'd be very unexpected for it to be 'bar foo bar bar [Very bad!] bar', But that's what could happen if the . operator evaluated the RHS first... which fortunately it doesn't appear to. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 11:00:01 2025 UTC |
if ($a) { $s = "option A"; } else if ($b) { $s = "option B"; } else if ($c) { $s = "option C"; } else { $v = expensiveFunction(); $s = "Value is: {$v} other stringy stuff {$v}"; }