Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » PHP
  • » [PHP-DEV] Comparison: ('*' == 0) ... True or false [RSS Feed]

#1 March 11, 2008 11:23:19

Alexey Z.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Comparison: ('*' == 0) ... True or false


On 3/11/08, Scott McNaught <> wrote:
> I don't know whether to post this as a bug or not. But I was tricked when
> programming today.
>
> It seems that the character "*" is non-strictly equivalent to 0. Is this
> the correct behavior or am I missing something?
>
> Test case:
>
> <?php
>
> var_dump('*' == 0);
>
> ?>
>
> Shows boolean(true).
>
> I was unable to find any documentation as to why this would be the case.

try

<?php
echo intval("*");
?>

that should explain the situation ;)

--
Alexey Zakhlestinhttp://blog.milkfarmsoft.com/--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#2 March 11, 2008 11:25:57

Pierre J.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Comparison: ('*' == 0) ... True or false


On Tue, Mar 11, 2008 at 11:17 AM, Scott McNaught
<> wrote:
> Hey guys,
>
> I don't know whether to post this as a bug or not. But I was tricked when
> programming today.
>
> It seems that the character "*" is non-strictly equivalent to 0. Is this
> the correct behavior or am I missing something?
>
> Test case:
>
> <?php
>
> var_dump('*' == 0);
>
> ?>
>
> Shows boolean(true).
>
> I was unable to find any documentation as to why this would be the case.http://www.php.net/manual/en/language.operators.comparison.php--
Pierrehttp://blog.thepimp.net|http://www.libgd.org--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#3 March 11, 2008 11:45:53

Scott M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Comparison: ('*' == 0) ... True or false


"If you compare an integer with a string, the string is converted to a
number. If you compare two numerical strings, they are compared as
integers." Well... I just feel stupid now :)

I am writing something which is extracting parts of a crontab. The variable
contained "*" was being compared to 0.

This would have clicked for me had it been anything else, but because it was
"*" my thoughts were that there was some new wild-card thing going on that I
hadn't heard about.

Cheers guys and sorry for my dumb post!

Scott

-----Original Message-----
From: Pierre Joye
Sent: Tuesday, March 11, 2008 8:25 PM
To: Scott McNaught
Cc: intern***@*ists.php.net
Subject: Re: Comparison: ('*' == 0) ... True or false

On Tue, Mar 11, 2008 at 11:17 AM, Scott McNaught
<> wrote:
> Hey guys,
>
> I don't know whether to post this as a bug or not. But I was tricked
when programming today.
>
> It seems that the character "*" is non-strictly equivalent to 0. Is this
the correct behavior or am I missing something?
>
> Test case:
>
> <?php
>
> var_dump('*' == 0);
>
> ?>
>
> Shows boolean(true).
>
> I was unable to find any documentation as to why this would be the case.http://www.php.net/manual/en/language.operators.comparison.php--
Pierrehttp://blog.thepimp.net|http://www.libgd.org--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

  • Root
  • » PHP
  • » [PHP-DEV] Comparison: ('*' == 0) ... True or false [RSS Feed]

Board footer

Moderator control

Enjoy the 16th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support