Shortening the statements containing "->" ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Herb Kauhry

    Shortening the statements containing "->" ?

    Just got into PHP. Bought and read Core PHP Programming by Atkinson and
    Suraski. I have a question that didn't seem to be addressed there or
    anywhere else I've looked so far. So the answer is probably "can't do it".
    Well here goes:

    Is it possible to specify a "shortcut" to

    xyzzy->firstthing = pflugh;
    xyzzy->nextthing = fnord;

    (like in ASP where you can say

    WITH xyzzy
    .firstthing = pflugh
    .nextthing = fnord
    END WITH

    (Yes, I am "converting " - from the ASP religion to the PHP religion!)

    It may be there and I just don't realize what it is called in PHP. I didn't
    see it. My first excursion into PHP resulted in some really l-o-n-g lines
    that would have been nice (lot's less typing) if I could have made them
    shorter somehow.

    thanks
    --



  • Terence

    #2
    Re: Shortening the statements containing "->" ?

    no.

    no shortcut.

    can't be done.

    why don't you show us the code, can we can see if it is possible to make
    it shorter.

    Comment

    • Herb Kauhry

      #3
      Re: Shortening the statements containing "->" ?

      Thanks. That's basically the code, only I have much longer variable names
      (I'm stuck with that), and 2 or 3 -> levels as well.

      I see there is no harm in wrapping the lines so I'll do that to make it all
      readable without scrolling left-right.



      --

      "Terence" <tk.lists@fastm ail.fm> wrote in message news:3fb9ae0a$1 @herald...[color=blue]
      > no.
      >
      > no shortcut.
      >
      > can't be done.
      >
      > why don't you show us the code, can we can see if it is possible to make
      > it shorter.
      >[/color]


      Comment

      • Kevin Thorpe

        #4
        Re: Shortening the statements containing &quot;-&gt;&quot; ?

        Herb Kauhry wrote:[color=blue]
        > Just got into PHP. Bought and read Core PHP Programming by Atkinson and
        > Suraski. I have a question that didn't seem to be addressed there or
        > anywhere else I've looked so far. So the answer is probably "can't do it".
        > Well here goes:
        >
        > Is it possible to specify a "shortcut" to
        >
        > xyzzy->firstthing = pflugh;
        > xyzzy->nextthing = fnord;
        >
        > (like in ASP where you can say
        >
        > WITH xyzzy
        > .firstthing = pflugh
        > .nextthing = fnord
        > END WITH[/color]

        You could use:

        $a = &$xyzzy;
        $a->firstthing = "pflugh";
        $a->nextthing = "fnord";

        it's not particularly clever though.

        Comment

        • Terence

          #5
          Re: Shortening the statements containing &quot;-&gt;&quot; ?

          Herb Kauhry wrote:
          [color=blue]
          > Thanks. That's basically the code, only I have much longer variable names
          > (I'm stuck with that), and 2 or 3 -> levels as well.
          >
          > I see there is no harm in wrapping the lines so I'll do that to make it all
          > readable without scrolling left-right.
          >
          >
          >[/color]
          yeah alright, Kevin's idea of using a proxy variable may be worth the
          extra line then.

          $obj4Ref =& $obj1->obj2->obj3->obj4;

          $obj4Ref->firstthing = $foo;
          $obj4Ref->nextthing = $bar;

          notice that the proxy variable $obj4Ref is now a direct "reference" to
          the $obj4 instance due to the "&" (reference) operator.


          Comment

          Working...