473,385 Members | 1,379 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,385 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 1599
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 : ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.