By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,350 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,350 IT Pros & Developers. It's quick & easy.

function call in double quote doesn't work

P: 51
With PHP 5, why doesn't it work as following. It always shows "--->" instead of "--->zzz".

Expand|Select|Wrap|Line Numbers
  1. $aa = "--->{${getName()}}";
  2. echo $aa;
  3.  
  4. function getName(){
  5.     return 'zzz';
  6. }
  7.  
Jack
Oct 17 '08 #1
Share this Question
Share on Google+
3 Replies


Atli
Expert 5K+
P: 5,058
Jack.

Please use [code] tags when posting your code examples.

[code=php] ... PHP code goes here ... [/code]

Thank you.
Moderator
Oct 17 '08 #2

Atli
Expert 5K+
P: 5,058
You can only use variables, array elements and object properties inside double quotes.

But... you can use the return value of a function or a method to dynamically get a variable name.

Consider this:
Expand|Select|Wrap|Line Numbers
  1. function getVarName() {
  2.     return 'zzz';
  3. }
  4. $zzz = 'Var value';
  5. echo "Value of variable = {${getVarName()}}";
  6.  
  7. // Prints: Value of variable = Var value
  8.  
See Variable variables to see how that works.
Oct 17 '08 #3

P: 51
Thank you so much, Moderator. I will remember to code php code before post. Now I understand how it works on functions return value in double quote. Why do I ask this is because I want to insert some values returned from functions in here-document. Now, only way to do is setting variables from functions then include those variables in here-document.
Jack
Oct 17 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.