When no value for placeholder is found in array, a default empty value is used if not otherwise specified.
Example:
$sprintfString = "This is %{what}! %{what}? This is %{place}!";
$assocArray = array(
'what' => 'madness',
'place' => 'Sparta'
);
Result:
'This is madness! madness? This is Sparta!'
/** * @test */ public function shouldSprintfStringAndReplaceWithEmptyIfNoPlaceholderFound() { //given $sprintfString = "This is %{what}! This is %{place}! No, this is invalid %{invalid_placeholder} placeholder!"; $assocArray = array('what' => 'madness', 'place' => 'Sparta'); //when $resultString = Strings::sprintAssocDefault($sprintfString, $assocArray); //then $this->assertEquals('This is madness! This is Sparta! No, this is invalid placeholder!', $resultString); }