Am I allowed to put single quoted, double quoted heredoc syntax or nowdoc syntax strings directly into functions whose parameters require a string like for example strlen('string text')
or strlen("some more string text")
instead of including a variable for example strlen($str);
?
If not why?
Yes. You can. You do not need to store it in a variable
Yes, you can use any syntax for creating strings.
Note, however, that you have to be careful when using heredoc/nowdoc syntax with function calls: the final line of the string can't contain anything except the identifier:
var_dump(<<<HERE
foo
HERE
);
You are allowed to do that unless function expects string variable to be passed by reference:
// '&' means that argument is passed by reference
function requestStringAsVariable(&$str) {
$str = '*' . $str . '*';
}
$str = 'test';
requestStringAsVariable($str);
echo $str; // outputs '*test*';
requestStringAsVariable('foo'); // won't work, as function expects variable