473,396 Members | 1,816 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,396 software developers and data experts.

Long String Contstants in Class Definitions

Hi,

I have a question about defining long string constants in class
defintions.

For an example, let's say I have some long SQL queries that I'd like
to store in a class. Furthermore, I don't want to instantiate the
class to use them since they're just a group of constants.

I can see a couple ways to acheive this, but they all leave unreadable
code. I can:

1) put the whole string all in one line, ignoring wrapping:

class MyQueries {
var $query1 = "SELECT this FROM that WHERE blah AND blah AND
blah..."
}

2) leave the string open and close it on another line:

class MyQueries {
var $query1 = "SELECT this
FROM that
WHERE blah
AND blah
AND blah
..."
}

3) use heredoc syntax:

class MyQueries {
var $query1=<<<ENDH
SELECT this
FROM that
WHERE blah
AND blah
AND blah
...
ENDH;
}

I don't like any of these. The first and last make the source code
unreadable and the middle one includes all the whitespace and CRLF's
in the string, which I don't want.

Coming from a C background, I'd like to do this:

class MyQueries {
var $query1="SELECT this"
" FROM that"
" WHERE blah"
" AND blah"
" AND blah"
" ...";
}

But PHP doesn't seem to support that syntax (out of curiousity: why
not?), and since it's a class definition I can't use the '.' operator
to concatenate them.

Does anybody have a good solution? I'm afraid I'm just going to have
to give up on the "No instantiation" thing and just define them with
"." operators in a constructor, even though it seems unneccessary.

Thanks,
Andrew
Jul 17 '05 #1
1 1679

"Andrew Palumbo" <to*****@yahoo.com> wrote in message
news:3c**************************@posting.google.c om...
Hi,

I have a question about defining long string constants in class
defintions.

For an example, let's say I have some long SQL queries that I'd like
to store in a class. Furthermore, I don't want to instantiate the
class to use them since they're just a group of constants.
<snip>
Thanks,
Andrew


This is a good use for define(), since you effectively want static
constants. These concatenate fine.

define("X","This is a string".
" that needs to be longer".
" than comfortably fits on a line.");

Can't imagine why you'd want them class-specific, but at least this works.

You could always construct them in the constructor:
class c {
var $v;

function c() {
$v="This is a string".
" that needs to be longer".
" than comfortably fits on a line.";

echo $this->v;
}
}

I hadn't realised you couldn't do this with "var" variables' declaration,
but it makes sense I suppose.

Garp

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: JustSomeGuy | last post by:
I have a structure typedef struct { string a; string b; } atype; string ABC = ("123"); string DEF = ("456");
6
by: cppaddict | last post by:
It struck me as odd today that while class definitions require a semi-colon at the end, function definitions do not. I was curious if this small syntactic difference represents a larger conceptual...
2
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to...
3
by: Gionni | last post by:
I'm trying to sign a message using CrytpoAPI (I can't use CAPICOM because I have Biztalk could verify this sign). I'm traslating the example in MSDN library at...
9
by: rsine | last post by:
I have developed a program that sends a command through the serial port to our business system and then reads from the buffer looking for a number. Everything worked great on my WinXP system, but...
2
by: samuelberthelot | last post by:
Hi, I've got a table that contains a field of type nText. Eeach records contains in this field the source code of a html page, something like that...: ' <html> <head> <\head> <body...
9
by: esakal | last post by:
Hello, I'm programming an application based on CAB infrastructure in the client side (c# .net 2005) Since my application must be sequencally, i wrote all the code in the UI thread. my...
9
by: jerry.upstatenyguy | last post by:
I am really stuck on this. I am trying to write a string array containing a "word" and a "definition" to a class called Entry. Ultimately this will end up in another class called dictionary. No,...
73
by: Yevgen Muntyan | last post by:
Hey, I was reading C99 Rationale, and it has the following two QUIET CHANGE paragraphs: 6.5.3.4: "With the introduction of the long long and extended integer types, the sizeof operator may...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.