473,698 Members | 2,601 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1693

"Andrew Palumbo" <to*****@yahoo. com> wrote in message
news:3c******** *************** ***@posting.goo gle.com...
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","Thi s 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
2240
by: JustSomeGuy | last post by:
I have a structure typedef struct { string a; string b; } atype; string ABC = ("123"); string DEF = ("456");
6
1525
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 difference between these two language constructs. I know that a semi-colon is used to "end a statement," but why would a function definition not be considered a statement, while a class def is? If there is a larger conceptual difference...
2
3787
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 produce two messages having the same message digest. That conjecture is false, as demonstrated by Wang, Feng, Lai and Yu in 2004 . Just recently, Wang, Yu, and Lin showed a short- cut solution for finding collisions in SHA-1 . Their result
3
9895
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 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/security/security/example_c_program_signing_a_message_and_verifying_a_message_signature.asp I tried this: // CERT_CONTEXT private struct CERT_CONTEXT
9
7131
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 when I tried the program on the Win98 system it will be running on, I get the following error: Cast from string "2076719" to type 'Long' is not valid I am not sure why I only get this error on the Win98 system or how to go about correcting...
2
1161
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 onload="bodyLoad()" > <div>
9
3267
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 problem occurs when i try to show a progress bar. The screen freezes. I know i'm not the first one to ask about it. but i'm looking
9
2095
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, this is not a homework assignment. In fact it was a question on my class midterm that everyone bombed. Unfortunately we never covered this in class prior to the midterm. Anyway, please help if you would be so kind. Here is what I have. I...
73
7410
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 yield a value that exceeds the range of an unsigned long." 6.5.6: "With the introduction of the long long and extended integer
0
8611
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8904
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8876
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7741
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6531
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5867
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2341
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.