Re: [PHP-DEV] PHP 4.0 Bug #9186 Updated: string compare with "==" does not work correctly

2001-02-09 Thread Alan van den Bosch



> As much as I hate to be wrong, I have to say that you are correct.

Maybe I'm missing something very subtle here, but I think your first
apraisal was correct Zak.

> > I think there is no reason to convert any type if both
> > operands of the comparision are of the same type. It costs
> > time and it's completely not necessary. This is a bug.

This issue arises from the loose typing in PHP with the introduction of
first class boolean type (the true and false keywords), from my
understanding the sematics being applied here are as follows (poetic license
applied liberally);

== is (has become?) a boolean logic operator, dealing in terms of  'true'
and 'false' values, so its terms are type cast to either 'true' or 'false'.
When applied to strings, a 'false' string is zero length or contains '0',
all other strings are 'true'.
[please dont ask 'what if the string is NULL... ;-)]

If you dont want your terms to be treated as (type cast to) boolean values
use the strict equallity operator ===

> > I can not see any description of this behavior in the
> > manual. The string type section descibes only what is
> > happen if a string is converted.

The manual doesnt seem very clear on this at all, but == behaves something
like ^(A xor B)


regards

alan.


-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] PHP 4.0 Bug #9186 Updated: string compare with "==" does not work correctly

2001-02-09 Thread Alan van den Bosch


OK, I was way off base in my reasoning... :-)

Thanks for the clarification Zeev and Zak.

Alan.

> How is this? I modified what Zeev said a wee bit:
>
> == is a 'loose' comparison operator [1].
>
> In most cases, this is more convenient - the operator does the right thing
> without needing any coaxing.  In some cases, things will happen that are
> confusing - particularly when comparing values that have leading zeros (0)
> or when comparing very long numbers that are inside a string.
>
> The basic rule to follow is this:
>
> Character-by-character comparison is performed only if both arguments are
> strings and at least one of the strings does not look like a number [2].
>
> Another way to state this rule is:
>
> - If at least one of the arguments is not a string, a numeric comparison
is
> made.
>
> - If both arguments are strings, but both of them look like numbers, a
> numeric comparison is made.
>
> - If both arguments are strings (and at least one of them doesn't look
like
> a number), a string comparison is made.
>
> [1] If you need to perform an exact comparison between two values, take a
> look at the 'strict' comparison operator (===) and the strcmp() function.
>
> [2] See the manual section on types and strings to learn what rules PHP
> follows for recognising numbers within strings.
>
> (Thanks to Zeev for clarifying this issue.)
>
> --zak



-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] PHP 4.0 Bug #9253: Class constructors can't return values

2001-02-15 Thread Alan van den Bosch

If Nathan's suggestion is not just an unreliable side effect, maybe this
should be documented. (ie changed from Feature/Change request)

regards,

Alan.

- Original Message -
From: "Nathan Cassano" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Thursday, February 15, 2001 11:11 AM
Subject: RE: [PHP-DEV] PHP 4.0 Bug #9253: Class constructors can't return
values


> You can return a value from a class constructor. It's just not that
obvious.
>
> class myclass {
>
> function myclass() {
>
> if($err){
> $this = $err;
> return;
> }
> }
>
> }
>
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, February 14, 2001 2:23 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP-DEV] PHP 4.0 Bug #9253: Class constructors can't return
> values
>
>
> From: [EMAIL PROTECTED]
> Operating system: All
> PHP version:  4.0.4pl1
> PHP Bug Type: Feature/Change Request
> Bug description:  Class constructors can't return values
>
> Class constructors can't abort instance creation, for example by returning
> false...
> This leads to a lot of "if (! $newobj->status)" crap.
> Why is that ? I found a message on the PHP3 mailing list about this, but
> it's still not there.
>
>
> --
> Edit Bug report at: http://bugs.php.net/?id=9253&edit=1
>
>
>
>
> --
> PHP Development Mailing List 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>


-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]