RE: [PHP-DEV] Possible problem in the parser

2003-03-15 Thread Marcus Börger
At 13:01 14.03.2003, Ford, Mike   [LSS] wrote:
 Just to make this completely clear, in left-associative PHP
 
 b = a==1? 4:a==2? 5:6;
 
 is equivalent to
 
 b = (a==1? 4:a==2)? 5:6;


 NO it is not equal. Either '==' has higher precedence OR '?:' has.
 See one of my previous mails where i showed where the error is.
Yes, it is -- believe me, I've researched this extensively.  It is NOT 
about precedence, but associativity.  If you want me to be totally 
completist about this:

Starting from:

   b = a==1? 4:a==2? 5:6;

precedence rules make this equivalent to:

   b = (a==1)? 4:(a==2)? 5:6;

but this is still ambiguous -- which ?: phrase do you evaluate 
first?  Associativity provides the answer: in PHP, where ?: is left 
associative (i.e. the left most ?: is evaluated first), the result is 
equivalent to:

   b = ((a==1)? 4:(a==2))? 5:6;

On the other hand, in c, where ?: is right associative, the equivalent is:

   b = (a==1)? 4:((a==2)? 5:6);

which, apart from the additional (unnecessary) parentheses around the == 
comparisons, is exactly what I said before.

QED


Ok Mike, i did not took left association into accound becuase it is stupid.
Since the whole thing is messy at the moment and there is no reason to
keep BC for messy things which shouldn't be done anyway i suppose we
make ir right associative.
Andi?

marcus

--
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP-DEV] Possible problem in the parser

2003-03-14 Thread Ford, Mike [LSS]
 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
 Sent: 13 March 2003 19:33
 To: Ford, Mike [LSS]
 Cc: 'Andrey Hristov'; [EMAIL PROTECTED]
 Subject: RE: [PHP-DEV] Possible problem in the parser
 
 
 At 14:58 13.03.2003, Ford, Mike   [LSS] wrote:
 
 Just to make this completely clear, in left-associative PHP
 
 b = a==1? 4:a==2? 5:6;
 
 is equivalent to
 
 b = (a==1? 4:a==2)? 5:6;
 
 
 NO it is not equal. Either '==' has higher precedence OR '?:' has.
 See one of my previous mails where i showed where the error is.

Yes, it is -- believe me, I've researched this extensively.  It is NOT about 
precedence, but associativity.  If you want me to be totally completist about this:

Starting from:

   b = a==1? 4:a==2? 5:6;

precedence rules make this equivalent to:

   b = (a==1)? 4:(a==2)? 5:6;

but this is still ambiguous -- which ?: phrase do you evaluate first?  Associativity 
provides the answer: in PHP, where ?: is left associative (i.e. the left most ?: is 
evaluated first), the result is equivalent to:

   b = ((a==1)? 4:(a==2))? 5:6;

On the other hand, in c, where ?: is right associative, the equivalent is:

   b = (a==1)? 4:((a==2)? 5:6);

which, apart from the additional (unnecessary) parentheses around the == comparisons, 
is exactly what I said before.

QED

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DEV] Possible problem in the parser

2003-03-14 Thread Andi Gutmans
You are right that it doesn't behave the same as C. However, personally 
although it might have been better for it to work like C I don't think it's 
a good idea to change it now. First of all it would break backwards 
compatibility in a way which would be hard for people to find where the bug 
is and how to fix it. Secondly, not meaning to insult anyone here, but I 
think people who write such code without using parentheses should improve 
their coding style :)

Andi

At 12:01 PM 3/14/2003 +, Ford, Mike   [LSS] wrote:
 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
 Sent: 13 March 2003 19:33
 To: Ford, Mike [LSS]
 Cc: 'Andrey Hristov'; [EMAIL PROTECTED]
 Subject: RE: [PHP-DEV] Possible problem in the parser


 At 14:58 13.03.2003, Ford, Mike   [LSS] wrote:

 Just to make this completely clear, in left-associative PHP
 
 b = a==1? 4:a==2? 5:6;
 
 is equivalent to
 
 b = (a==1? 4:a==2)? 5:6;


 NO it is not equal. Either '==' has higher precedence OR '?:' has.
 See one of my previous mails where i showed where the error is.
Yes, it is -- believe me, I've researched this extensively.  It is NOT 
about precedence, but associativity.  If you want me to be totally 
completist about this:

Starting from:

   b = a==1? 4:a==2? 5:6;

precedence rules make this equivalent to:

   b = (a==1)? 4:(a==2)? 5:6;

but this is still ambiguous -- which ?: phrase do you evaluate 
first?  Associativity provides the answer: in PHP, where ?: is left 
associative (i.e. the left most ?: is evaluated first), the result is 
equivalent to:

   b = ((a==1)? 4:(a==2))? 5:6;

On the other hand, in c, where ?: is right associative, the equivalent is:

   b = (a==1)? 4:((a==2)? 5:6);

which, apart from the additional (unnecessary) parentheses around the == 
comparisons, is exactly what I said before.

QED

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211
--
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP-DEV] Possible problem in the parser

2003-03-14 Thread Jani Taskinen
On Fri, 14 Mar 2003, Andi Gutmans wrote:

You are right that it doesn't behave the same as C. However, personally 
although it might have been better for it to work like C I don't think it's 
a good idea to change it now. First of all it would break backwards 
compatibility in a way which would be hard for people to find where the bug 
is and how to fix it. Secondly, not meaning to insult anyone here, but I 
think people who write such code without using parentheses should improve 
their coding style :)

Amen. :)

--Jani


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DEV] Possible problem in the parser

2003-03-14 Thread Ford, Mike [LSS]
 -Original Message-
 From: Andi Gutmans [mailto:[EMAIL PROTECTED]
 Sent: 14 March 2003 14:50
 
 You are right that it doesn't behave the same as C. However, 
 personally 
 although it might have been better for it to work like C I 
 don't think it's 
 a good idea to change it now. First of all it would break backwards 
 compatibility in a way which would be hard for people to find 
 where the bug 
 is and how to fix it. Secondly, not meaning to insult anyone 
 here, but I 
 think people who write such code without using parentheses 
 should improve 
 their coding style :)

Oh, I totally agree.  My original response was to a query as to whether the
PHP behaviour was a bug -- so I simply pointed out (in some detail!) that,
although different from c, it *did* conform to the precedence and
associativity documented in the PHP manual.

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DEV] Possible problem in the parser

2003-03-13 Thread Ford, Mike [LSS]
 -Original Message-
 From: Andrey Hristov [mailto:[EMAIL PROTECTED]
 Sent: 12 March 2003 17:26
 
  On Wed, 12 Mar 2003, Andrey Hristov wrote:
 
Few minutes ago I found the following behaviour somehow 
 wierd for me :
 
  Known bug, the associativity of the ternary operator has been
  broken since ages in the engine.  It's on the won't be
  fixed sheet, because of BC concerns.

That's a bit hard -- it's different from c, certainly (left associative
instead of right), but that's a valid choice (even if it was originally
accidental!) and calling it broken is a bit harsh.

 
 Is it documented somewhere?

Yes -- at
http://www.php.net/manual/en/language.operators.php#language.operators.prece
dence).

Just to make this completely clear, in left-associative PHP

   b = a==1? 4:a==2? 5:6;

is equivalent to

   b = (a==1? 4:a==2)? 5:6;

yielding 5 if a==1 or a==2, else 6.

But in right-associative c, it's equivalent to:

   b = a==1? 4:(a==2? 5:6);

yielding 4 if a==1, 5 if a==2, else 6.

Since this *is* documented behaviour, I don't see how it can be called
particularly unexpected.  (Weird, maybe, if you're used to the c
behaviour, but not unexpected!)

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DEV] Possible problem in the parser

2003-03-13 Thread Marcus Börger
At 14:58 13.03.2003, Ford, Mike   [LSS] wrote:

Just to make this completely clear, in left-associative PHP

   b = a==1? 4:a==2? 5:6;

is equivalent to

   b = (a==1? 4:a==2)? 5:6;


NO it is not equal. Either '==' has higher precedence OR '?:' has.
See one of my previous mails where i showed where the error is.
marcus

--
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DEV] Possible problem in the parser

2003-03-12 Thread Andrey Hristov
 Few minutes ago I found the following behaviour somehow wierd for me :
?php
$a = 1;
$b = $a==1? 4:$a==2? 5:6;
printf(a[%d]b[%d]\n, $a, $b);
?
Prints : 
a[1]b[5]

Similar C program :
main()
{
int a,b;
a = 1;
b = a==1? 4:a==2? 5:6;
printf(a[%d]b[%d]\n, a, b);
}
Prints : 
a[1]b[4]

-=-=-=-=-=-
I think that the behavior of the C program is the right

Andrey





-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Possible problem in the parser

2003-03-12 Thread Sascha Schumann
On Wed, 12 Mar 2003, Andrey Hristov wrote:

  Few minutes ago I found the following behaviour somehow wierd for me :

Known bug, the associativity of the ternary operator has been
broken since ages in the engine.  It's on the won't be
fixed sheet, because of BC concerns.

- Sascha

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Possible problem in the parser

2003-03-12 Thread Andrey Hristov
- Original Message - 
From: Sascha Schumann [EMAIL PROTECTED]
To: Andrey Hristov [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Wednesday, March 12, 2003 7:21 PM
Subject: Re: [PHP-DEV] Possible problem in the parser


 On Wed, 12 Mar 2003, Andrey Hristov wrote:
 
   Few minutes ago I found the following behaviour somehow wierd for me :
 
 Known bug, the associativity of the ternary operator has been
 broken since ages in the engine.  It's on the won't be
 fixed sheet, because of BC concerns.
 

h


Andrey


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Possible problem in the parser

2003-03-12 Thread Andrey Hristov
 On Wed, 12 Mar 2003, Andrey Hristov wrote:

   Few minutes ago I found the following behaviour somehow wierd for me :

 Known bug, the associativity of the ternary operator has been
 broken since ages in the engine.  It's on the won't be
 fixed sheet, because of BC concerns.

Is it documented somewhere? If not then isn't this an undocumeted feature
and
those relying on undocumented features are playing with fire.

Andrey


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Possible problem in the parser

2003-03-12 Thread Derick Rethans
On Wed, 12 Mar 2003, Andrey Hristov wrote:

  Few minutes ago I found the following behaviour somehow wierd for me :
 ?php
 $a = 1;
 $b = $a==1? 4:$a==2? 5:6;
 printf(a[%d]b[%d]\n, $a, $b);
 ?
 Prints : 
 a[1]b[5]
 
 Similar C program :
 main()
 {
 int a,b;
 a = 1;
 b = a==1? 4:a==2? 5:6;
 printf(a[%d]b[%d]\n, a, b);
 }
 Prints : 
 a[1]b[4]
 
 -=-=-=-=-=-
 I think that the behavior of the C program is the right

It's just a different operator precedence; it's not really wrong, just 
different.

Derick

-- 
my other box is your windows PC
-
 Derick Rethans http://derickrethans.nl/ 
 PHP Magazine - PHP Magazine for Professionals   http://php-mag.net/
-

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Possible problem in the parser

2003-03-12 Thread Marcus Börger
At 18:42 12.03.2003, Derick Rethans wrote:
On Wed, 12 Mar 2003, Andrey Hristov wrote:

  Few minutes ago I found the following behaviour somehow wierd for me :
 ?php
 $a = 1;
 $b = $a==1? 4:$a==2? 5:6;
 printf(a[%d]b[%d]\n, $a, $b);
 ?
 Prints :
 a[1]b[5]

 Similar C program :
 main()
 {
 int a,b;
 a = 1;
 b = a==1? 4:a==2? 5:6;
 printf(a[%d]b[%d]\n, a, b);
 }
 Prints :
 a[1]b[4]

 -=-=-=-=-=-
 I think that the behavior of the C program is the right
It's just a different operator precedence; it's not really wrong, just
different.


Where is the different precednece here? I can only find an error.
Lets support parantesis:
ALL BUT PHP)  '==' has higher precedence than '?:'

((a==1) ? 4 : ((a==2) ? 5 : 6))  = (1) ? 4 : ((0) ? 5 : 6) = 1 ? 4 : 6 = 4

PHP?) '?:' has higher precedence than '=='

(a == (1 ? 4 : a) == (2 ? 5 : 6))

( a == (4) == (5))

Now what? Assume order left from to right: ( (a == (4)) == (5) = (0 == 5) = 0

Or right to left (which contradicts rest of PHP behavior): ( a == ((4) == 
(5))) = (a == 0) = 0

Result: This is (to say it in german mumpitz) wrong.

So lets fix it.

marcus



--
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php