I missed that you are discussing about transitivity. Your claim sound fair to
me too. I'm relatively new to PHP :) So I'm not sure, but it's probably because
historical reason that PHP dose not have transitivity for equality operator.
We can still workaround with type casting, though.
Do you know annotated manual?
http://www.php.net/manual/en/
Your post would be a great note for many users. How about add them to sections
that I've been mentioned.
"Yasuo Ohgaki" <[EMAIL PROTECTED]> wrote in message news:...
> PHP has type juggling feature. PHP4 supports "total equality"(?) operator
"===".
> If you need variable to be match for both type and value. Use "===", then you
> can avoid type juggling.
>
> http://www.php.net/manual/en/language.types.type-juggling.php
> http://www.php.net/manual/en/language.operators.comparison.php
>
> Regards,
> --
> Yasuo Ohgaki
>
> > I'm sure you appreciate the importance of transitive equality in programming
> > languages (especially they all aspire to be pseudo-mathematical), which is
> > why I think you'll appreciate this.
> >
> > <?php
> >
> > $a = "0";
> > $b = 0;
> > $c = "";
> > $d = " ";
> >
> > $a == $b // T
> > $b == $c // T
> > $a == $c // F!!
As you mentioned it's worth to note. Since $a and $d is string that have
different content, so PHP evaluates it as FALSE.
> >
> > $b == $c // T
> > $b == $d // T
> > $c == $d // F!!
This is the same.
> >
> > ?>
> >
> > Perl, of course, outputs the expected values: $a, $b, $c and $d are equal
> > under '==', and only $a and $b are equal under 'eq'. PHP's '===' operator
> > (its equivalent to 'eq') says that $a, $b, $c and $d are all different.
It also worh to note.
=== expects the same type although PHP loosely typed language.
> >
> > Doesn't that seem like a fundamental flaw? How can equality NOT be
> > transitive?? How can anyone be expected to write programs in such an
> > environment?
We still can cast variables, so I suggest cast when you needed.
Regards,
--
Yasuo Ohgaki
--
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]