473,399 Members | 2,774 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,399 software developers and data experts.

Class variable interpolation

Hi,

Does anyone know the correct syntax to interpolate a class variable, $x
say, inside a string? I tried

"{self::$x}"

but it produces the string

{self::x}
August
Oct 28 '08 #1
5 4442
On Tue, 28 Oct 2008 01:58:40 +0100, August Karlstrom
<fu********@gmail.comwrote:
Hi,

Does anyone know the correct syntax to interpolate a class variable, $x
say, inside a string? I tried

"{self::$x}"

but it produces the string

{self::x}
Here it will produce '{self::}', and a notice $x isn't set.
AFAIK, with static variables, one has the same 'problem' as with
constants: no interpolation possible, just use temporary variables or
concatenation.
--
Rik
Oct 28 '08 #2
Rik Wasmus wrote:
On Tue, 28 Oct 2008 01:58:40 +0100, August Karlstrom
<fu********@gmail.comwrote:
>Hi,

Does anyone know the correct syntax to interpolate a class variable,
$x say, inside a string? I tried

"{self::$x}"

but it produces the string

{self::x}

Here it will produce '{self::}', and a notice $x isn't set.
AFAIK, with static variables, one has the same 'problem' as with
constants: no interpolation possible,
If that is the case it was probably overlooked by the language
developers. I see no reason why static variables could not be
interpolated with the syntax above.
just use temporary variables or concatenation.
Right, but it is kind of clumsy.
August
Oct 28 '08 #3
August Karlstrom wrote:
Rik Wasmus wrote:
>On Tue, 28 Oct 2008 01:58:40 +0100, August Karlstrom
<fu********@gmail.comwrote:
>>Hi,

Does anyone know the correct syntax to interpolate a class variable,
$x say, inside a string? I tried

"{self::$x}"

but it produces the string

{self::x}

Here it will produce '{self::}', and a notice $x isn't set.
AFAIK, with static variables, one has the same 'problem' as with
constants: no interpolation possible,

If that is the case it was probably overlooked by the language
developers. I see no reason why static variables could not be
interpolated with the syntax above.
>just use temporary variables or concatenation.

Right, but it is kind of clumsy.
Using sprintf() and its ilk is also viable, and, IMO, can be easier on
the eyes than relying on variable interpolation, anyway.
August
--
Curtis
$eMail = str_replace('sig.invalid', 'gmail.com', $from);
Oct 29 '08 #4
Curtis wrote:
Using sprintf() and its ilk is also viable, and, IMO, can be easier on
the eyes than relying on variable interpolation, anyway.
For shorter strings, yes, but probably not with 50 lines of HTML in a
heredoc.
August
Oct 29 '08 #5

"August Karlstrom" <fu********@gmail.comwrote in message
news:ge**********@aioe.org...
Curtis wrote:
>Using sprintf() and its ilk is also viable, and, IMO, can be easier on
the eyes than relying on variable interpolation, anyway.

For shorter strings, yes, but probably not with 50 lines of HTML in a
heredoc.
A heredoc is your case for code legibility? :^)
Oct 29 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Peter Horst | last post by:
I have a tiny custom 404 script I'm working on; I'd like to imitate the standard Apache 404 page insofar as I'd like "Apache/1.3.29 Server at www.example.com Port 80" to appear below my 404...
3
by: red | last post by:
within an object function, this code: $test2='test'; echo "$test"; $this->test2='test2'; echo "$this->test2\n"; produces this result: test2
7
by: bartek | last post by:
Hello, I've been pondering with this for quite some time now, and finally decided to ask here for suggestions. I'm kind of confused, actually... Maybe I'm thinking too much... Brain dump...
14
by: Charles Banas | last post by:
I'm not sure if this is the right place to ask about this, but I've seen several posts in the past regarding Akima's Bivariate Interpolations routines, and i'm wondering if someone can give me some...
3
by: Jonas Ernst | last post by:
Hi, Can somebody give me some hints how to do a line interpolation without using floating point arithemtics? The function shall do a linear interpolation between 2 points (line interp?) and...
4
by: Jason Dunbar | last post by:
Hi there.. I am wondering if it is possible to interpolate the value of a variable to reference a variable to gain its value. For example:- if I have a series of variables:- var01
8
by: Jerry | last post by:
I am a MySQL and PHP newbie. I am having trouble getting the $w variable in my code below passed to mysql. When I use the value of $w directly in the Where clause, the correct rows are returned....
10
by: John Passaniti | last post by:
(Note: This is not the same message I posted a week or so ago. The problem that prevented my previous attempt to work was a silly error in the template system I was using. This is a problem...
4
by: yash0101 | last post by:
I have a hash , and in the value part of that (which is a string , So that variable interpolation can happen) i have used a variable . Now later in the program i set this variable and try to...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.