473,406 Members | 2,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 1601
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 : ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.