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