Class variable interpolation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • August Karlstrom

    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
  • Rik Wasmus

    #2
    Re: Class variable interpolation

    On Tue, 28 Oct 2008 01:58:40 +0100, August Karlstrom
    <fusionfile@gma il.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

    Comment

    • August Karlstrom

      #3
      Re: Class variable interpolation

      Rik Wasmus wrote:
      On Tue, 28 Oct 2008 01:58:40 +0100, August Karlstrom
      <fusionfile@gma il.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

      Comment

      • Curtis

        #4
        Re: Class variable interpolation

        August Karlstrom wrote:
        Rik Wasmus wrote:
        >On Tue, 28 Oct 2008 01:58:40 +0100, August Karlstrom
        ><fusionfile@gm ail.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('si g.invalid', 'gmail.com', $from);

        Comment

        • August Karlstrom

          #5
          Re: Class variable interpolation

          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

          Comment

          • Jessica Griego

            #6
            Re: Class variable interpolation


            "August Karlstrom" <fusionfile@gma il.comwrote in message
            news:ge8e9n$ur2 $1@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? :^)


            Comment

            Working...