So my goal is to create a string of random letters, and the letters can be repeated in a string. So I thought I could be smart and do this:
$str = implode(
array_fill(0,10,
function(){
$c='abcdefghijklmnopqrstuvwxyz';
return (string)$c{rand(0,strlen($c)-1)};
}
)
);
echo $str;
But I get the following error:
Crop fatal error: object of class Closure cannot be converted for a string to ...
This is literally the only thing in my script, so no, this is not something else. Now the manual describes the third argument for array_fill: "The value to populate," and it is indicated as accepting a mixed type. Now I know that “mixed” does not necessarily equate to “any” type, but it seems reasonable to me that I should use an anonymous function as the third argument if it returns a string, right? But apparently, I can’t do this.
, , ; , , , . , , "" , "" , php ( ), , , - - ?