# php_stream_cast to fd

- Thread: https://externals.io/message/36092
- Original archive: https://news-web.php.net/php.internals/36092
- Started by Joe Orton on 2008-03-11T09:42:14+00:00
- Messages: 6
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #36092 — Joe Orton — 2008-03-11T09:42:14+00:00

URL: https://externals.io/message/36092#36092

When php_stream_cast is passed any of the _AS_FD-like options, what is 
the ret argument supposed to point to?  This does not seem to be decided 
consistently; from a quick survey:

ext/openssl/xp_ssl.c:
    php_openssl_sockop_cast() presumes that *ret has sizeof(void *)
ext/soap/php_http.c:
    stream_alive() presumes that *ret has sizeof(long)
ext/standard/streamfuncs.c:
    stream_array_from_fd_set() presumes that *ret has sizeof(php_socket_t)
main/streams/xp_socket.c:
    php_sockop_cast() presumes that *ret has sizeof(int)

On 64-bit platforms, of course, at least half of these cases will break, 
since sizeof(int) != sizeof(long).

This issue is the cause of http://bugs.php.net/bug.php?id=32979, where a 
64-bit value is being written to an pointer to a 32-bit value on the 
stack, and trashing whatever follows it.

joe

---

## #36093 — Scott McNaught [Synergy 8] — 2008-03-11T10:17:24+00:00

URL: https://externals.io/message/36092#36093 · In reply to: #36092

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.


Regards,

Scott

---

## #36094 — Alexey Zakhlestin — 2008-03-11T10:22:28+00:00

URL: https://externals.io/message/36092#36094

>  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 Zakhlestin
http://blog.milkfarmsoft.com/

---

## #36095 — Pierre Joye — 2008-03-11T10:25:10+00:00

URL: https://externals.io/message/36092#36095

On Tue, Mar 11, 2008 at 11:17 AM, Scott McNaught [Synergy 8]
<scott.mcnaught@synergy8.com> 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

--
Pierre
http://blog.thepimp.net | http://www.libgd.org

---

## #36096 — Scott McNaught [Synergy 8] — 2008-03-11T10:44:50+00:00

URL: https://externals.io/message/36092#36096 · In reply to: #36095

"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 [mailto:pierre.php@gmail.com] 
Sent: Tuesday, March 11, 2008 8:25 PM
To: Scott McNaught [Synergy 8]
Cc: internals@lists.php.net
Subject: Re: [PHP-DEV] Comparison: ('*' == 0) ... True or false

On Tue, Mar 11, 2008 at 11:17 AM, Scott McNaught [Synergy 8]
<scott.mcnaught@synergy8.com> 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

--
Pierre
http://blog.thepimp.net | http://www.libgd.org

---

## #36097 — Antony Dovgal — 2008-03-11T11:27:30+00:00

URL: https://externals.io/message/36092#36097 · In reply to: #36093

> 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?

http://www.php.net/manual/en/language.operators.comparison.php

Ask such questions in php-general@, please. Thank you.

-- 
Wbr, 
Antony Dovgal
