[PHP] bug in echo function?

2002-01-18 Thread Billy Harvey

I ran across a curious bug in the echo function this morning.  My PHP is
Debian binary 4.1.1-1.

The first example below does not work (it should draw a
checkerboard-like table):

-

html
head
titleChess/title
body
table border=1
?

for ($i=0 ; $i8 ; $i++) {
  echo tr align=center valign=center;
  for ($j=0 ; $j8 ; $j++) {
echo td . ($i*8)+$j . /td;
  }
  echo /tr\n;
}

?
/table
/body
/html

-

However, by changing the echo line to two echo lines, it works as
desired:

-

html
head
titleChess/title
body
table border=1
?

for ($i=0 ; $i8 ; $i++) {
  echo tr align=center valign=center;
  for ($j=0 ; $j8 ; $j++) {
echo td;
echo ($i*8)+$j . /td;
  }
  echo /tr\n;
}

?
/table
/body
/html

-

I don't see any limitations about concatenating strings in the man page
of the echo statement.  Perhaps this is a bug?

Billy



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] bug in echo function?

2002-01-18 Thread Darren Gamble

Good day,

The reason that the first statement doesn't work as intended is due to the
order that the operands are processed.

The operands in the line:

td . ($i*8)+$j . /td

are being processed like this:

(td . ($i*8))+($j . /td)

If you change the line to:

td . (($i*8)+$j) . /td

then you'll get the desired result.

Rule of thumb: Use parenthesis whenever you have a complex operation to
ensure the result is what you want.


Darren Gamble
Planner, Regional Services
Shaw Cablesystems GP
630 - 3rd Avenue SW
Calgary, Alberta, Canada
T2P 4L4
(403) 781-4948


-Original Message-
From: Billy Harvey [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 18, 2002 11:44 AM
To: php
Subject: [PHP] bug in echo function?


I ran across a curious bug in the echo function this morning.  My PHP is
Debian binary 4.1.1-1.

The first example below does not work (it should draw a
checkerboard-like table):

-

html
head
titleChess/title
body
table border=1
?

for ($i=0 ; $i8 ; $i++) {
  echo tr align=center valign=center;
  for ($j=0 ; $j8 ; $j++) {
echo td . ($i*8)+$j . /td;
  }
  echo /tr\n;
}

?
/table
/body
/html

-

However, by changing the echo line to two echo lines, it works as
desired:

-

html
head
titleChess/title
body
table border=1
?

for ($i=0 ; $i8 ; $i++) {
  echo tr align=center valign=center;
  for ($j=0 ; $j8 ; $j++) {
echo td;
echo ($i*8)+$j . /td;
  }
  echo /tr\n;
}

?
/table
/body
/html

-

I don't see any limitations about concatenating strings in the man page
of the echo statement.  Perhaps this is a bug?

Billy



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] bug in echo function?

2002-01-18 Thread Darren Gamble

Good day,

No, that's not it.

It's just a simple matter of order of operations.  You have an expression-
that expression needs to be evaluated into one thing, and that one thing is
then passed to echo() as the single argument.

I'm not a php expert, but evidently the . operator is evaluated before the
* operator, which in turn is evaluated before the + operator. 

Perhaps it would be easier to understand if you thought of the . operator
like the exponent operator in math- it is evaluated before * or + is.


Darren Gamble
Planner, Regional Services
Shaw Cablesystems GP
630 - 3rd Avenue SW
Calgary, Alberta, Canada
T2P 4L4
(403) 781-4948


-Original Message-
From: Billy Harvey [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 18, 2002 12:07 PM
To: Darren Gamble
Cc: php
Subject: RE: [PHP] bug in echo function?


On Fri, 2002-01-18 at 13:54, Darren Gamble wrote:
 Good day,
 
 The reason that the first statement doesn't work as intended is due to the
 order that the operands are processed.
 
 The operands in the line:
 
 td . ($i*8)+$j . /td
 
 are being processed like this:
 
 (td . ($i*8))+($j . /td)
 
 If you change the line to:
 
 td . (($i*8)+$j) . /td
 
 then you'll get the desired result.
 
 Rule of thumb: Use parenthesis whenever you have a complex operation to
 ensure the result is what you want.

Hmmm - so my assumption that the concatenation operator between the
strings gives them a delination equivalent to listing this as three
separate echo statements is incorrect, I take it.

Shouldn't the echo function process it in this manner from a standpoint
of consistency?

Thanks for the clarification.

Billy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] bug in echo function?

2002-01-18 Thread Billy Harvey

On Fri, 2002-01-18 at 13:54, Darren Gamble wrote:
 Good day,
 
 The reason that the first statement doesn't work as intended is due to the
 order that the operands are processed.
 
 The operands in the line:
 
 td . ($i*8)+$j . /td
 
 are being processed like this:
 
 (td . ($i*8))+($j . /td)
 
 If you change the line to:
 
 td . (($i*8)+$j) . /td
 
 then you'll get the desired result.
 
 Rule of thumb: Use parenthesis whenever you have a complex operation to
 ensure the result is what you want.

Hmmm - so my assumption that the concatenation operator between the
strings gives them a delination equivalent to listing this as three
separate echo statements is incorrect, I take it.

Shouldn't the echo function process it in this manner from a standpoint
of consistency?

Thanks for the clarification.

Billy


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]