472,985 Members | 2,751 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,985 software developers and data experts.

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
--

Jul 17 '05 #1
4 1586
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: TD | last post by:
I created a query in Access 2000 that runs perfectly. I then copied the "sql" version of the same query and set it equal the variable "sql" in the code below. When I run the code below I get an...
4
by: Lokicer | last post by:
Hi, i am a c newbie, i write some code to get size of structs i compile and run it in VC6.0 //#pragma pack(1) typedef struct tag_NullMsg { int a; } tNullMsg; typedef struct tag_CharMsg
1
by: tim | last post by:
trying to work with a directory in windows, that has "\a" in the full pathname this works: >>> c = string.replace('c:\content\ce\cw\cvd', '\\', '\\') >>> c 'c:\\content\\ce\\cw\\cvd' this...
7
by: bob | last post by:
Hi, I need to make a string containing this text litterally as it:: selectcommand="select * from table where field1=' " & myvar & " ' " Dim st as string st="selectcommand=" & ??? How can i...
0
by: SolaFide | last post by:
I have an XML doc that looks something like this: <?xml version="1.0" encoding="utf-8"?> <elem1> <elem2 xmlns="http://someurl.com"> <elem3> <item>some stuff here</item> ...
6
by: hasnain | last post by:
Dear All, I want to get text in the following format such as my number is written like 410-01-234-12334 and I want each of the them in a separate column, like 410 in one, 01 in another and so on....
3
by: jerinjoy | last post by:
Hi, I'm not very familiar with Perl but got around to using the GetOpt module. One of my inputs strings contains a '-' character, but I don't want the GetOpt to parse it. eg. my_perl_file -x...
2
by: TSIGOS1 | last post by:
HELLO, I need to insert records to an access table with vba code but the records have the " ' " in them, so the statement cannot be executed. what can i do? thanks a lot for your help.
0
by: lazukars | last post by:
I am building some code with msqli prepared statements via. The code will be used for a form that will send data to a MySql database. What I would like to know is how secure are prepared...
2
by: killy971 | last post by:
I am using java to validate an XML file with a DTD, without having the DVD declaration inside the original file, by setting the doctype dynamically to a transformer like this : ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.