tags:

views:

38

answers:

2

Hi,

Just wondering, would the following code arrangement cause any issues when calling mysql_connect, i.e.:

public function connect() {
    mysql_connect($this->host,
                  $this->username,
                  $this->password)
        or die("Could not connect. " . mysql_error());

or does it need to be all on one line, i.e.:

mysql_connect($this->host,$this->username,$this->password) or die("Could not connect. " . mysql_error());

Thanks.

A: 

no, whitespaces are ignored in php as they are in almost every other language (python being a special case, but you can still split lines in python)

knittl
True *most* languages don't care about line breaks, but there are still plenty that use line breaks as delimiters. BASIC variants (incl. VBScript), most shell scripting languages, Javascript to an extent (thanks to the insanely wrong "semicolon insertion" thing)...
T.J. Crowder
@t.j. crowder: well, in vb you can work around it by using the `_` operator, shell-scripts need to be escaped with `\` and javascript will always be a mystery ;) but you are right, not every language ignores whitespace
knittl
+3  A: 

Whitespace (which in this case includes newlines) between tokens is irrelevant. You could even make it look like this if you wanted

public
function
connect
(
)
{
mysql_connect
(
$this
->
host
,
$this
->
username
,
$this
->
password
)
or
die
(
"could not connect. "
.
mysql_error
(
)
)
;
}
Peter Bailey
+1 for correctness, +1 (if I could!) for humor ;-)
T.J. Crowder
+1 for seeing that for the first time.
zaf