ID:               49097
 User updated by:  mkrasuski at infico dot pl
 Reported By:      mkrasuski at infico dot pl
 Status:           Bogus
 Bug Type:         Output Control
 Operating System: Windows 7/XP
 PHP Version:      5.3.0
 New Comment:

Hi again,

> $false = false;
> if ((string)$false)) { die("oops"); }
> If the typecast made it return "false" 
> then you'd see the oops here.

You gave too abstract example. Personally I haven't seen such
construction. Most people, IMO, would rather do:

$string = '';
if( !((bool) $string) ) { die("oops"); }

Besides, I think, it's against the programming convention :)

> You need to be able to get consistent 
> behavior regardless of the cast

Well... doing (string)((int)((string) '153 foo')); you won't get '153
foo' as the result. So where's the "consistent behavior"? ;)


Previous Comments:
------------------------------------------------------------------------

[2009-07-29 12:37:45] [email protected]

You need to be able to get consistent behavior regardless of the cast,
not everyone is just printing the output.

$false = false;
if ((string)$false)) { die("oops"); }


If the typecast made it return "false" then you'd see the oops here.

------------------------------------------------------------------------

[2009-07-29 12:33:19] mkrasuski at infico dot pl

One more thing.

> false has to be an empty string to correctly evaluate to false. 
> No bug here.

May I ask, why? When casting '153 foo' to int you get 153. Why, when
casting 'false' (or 'FALSE', whatever) you get 1 (true), not 0 (false)?
PHP is a script language, it should the difference, IMO.)

------------------------------------------------------------------------

[2009-07-29 12:24:15] mkrasuski at infico dot pl

Ok about string. But what about casting to bool (same problem).)

------------------------------------------------------------------------

[2009-07-29 11:56:20] [email protected]

false has to be an empty string to correctly evaluate to false.  No bug
here.

------------------------------------------------------------------------

[2009-07-29 11:51:24] mkrasuski at infico dot pl

You missunderstood me. The cast of a bool(false) is "" but cast of a
bool(true) is "1". IMO it should be "false" and "true", or, at least "0"
and "1".)

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/49097

-- 
Edit this bug report at http://bugs.php.net/?id=49097&edit=1

Reply via email to