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

Class variable interpolation

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

"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 discussion thread is closed

Replies have been disabled for this discussion.