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

Shortening the statements containing "->" ?

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

Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


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

Jul 17 '05 #2

P: n/a
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******@fastmail.fm> wrote in message news:3fb9ae0a$1@herald...
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.

Jul 17 '05 #3

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


You could use:

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

it's not particularly clever though.

Jul 17 '05 #4

P: n/a
Herb Kauhry wrote:
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.

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.
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.