Reputation: 185
I am a bit confused about how to add an object to a string.
I am trying to add the $this->getUserId();
(which contains the userId of the user).
$fileName = "user_.$this->getUserId()".".$fileExt";
Upvotes: 0
Views: 126
Reputation: 109
You can concatenate the object in string using dot (.) operator
$fileName = "user_".$this->getUserId().".".$fileExt";
For more info about PHP string concatenation. You can check the PHP documentation.
http://php.net/manual/en/language.operators.string.php
Upvotes: 0
Reputation: 3260
This should work:
$fileName = "user_{$this->getUserId()}.$fileExt";
It should give you:
user_1.ext
See the PHP manual on strings, more specifically the part about curly braces and 'complex' parsing.
For normal variables you can place them in double quoted strings and they will be parsed. For more complex things like expressions you need to wrap them in {}
so that they will be parsed.
Upvotes: 0