473,395 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

function call in double quote doesn't work

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
3 6589
Atli
5,058 Expert 4TB
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
5,058 Expert 4TB
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
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

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

Similar topics

5
by: Yangang Bao | last post by:
I have a simple test program. It doesn't work. I want to know what is the reason and how to fix it. Maybe I should use template function to do it. But I don't know how. Here is the simple...
3
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules'...
2
by: Amadeus W. M. | last post by:
I have a bunch of templated functions: template <class Type_t> double f2(Type_t x) { return 2*x; } template <class Type_t> double f3(Type_t x) { return 3*x; }
10
by: Matthew Wilson | last post by:
Lately, I've been writing functions like this: def f(a, b): assert a in assert b in The point is that I'm checking the type and the values of the parameters.
18
by: tbringley | last post by:
I am a c++ newbie, so please excuse the ignorance of this question. I am interested in a way of having a class call a general member function of another class. Specifically, I am trying to...
5
by: StephQ | last post by:
This is from a thread that I posted on another forum some days ago. I didn't get any response, so I'm proposing it in this ng in hope of better luck :) The standard explanation is that pointer...
4
by: zaeminkr | last post by:
I got a good answer here I have still confusing part. I have two very simple classes class DRect { private : double x0, y0, x1, y1; public : DRect(double a, double b, double c, double d) :...
12
by: aaragon | last post by:
I have this scenario: several arrays for which I have their fixed values at compilation time. Now, at runtime I need to access a specific array depending on an integer but I want to avoid if and...
7
by: mathieu | last post by:
Hi there, I know this is not possible in c++. So my question, how should I rewrite the following piece of code (without using a dummy class which template parameter could be use for partial...
9
by: Yannick | last post by:
Hi everyone - I am not quite sure to understand what is really going on when a function defined in one translation unit calls a function defined in a different translation unit without knowing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.