# Source type.c says settype($var, "double") is deprecated

- Thread: https://externals.io/message/34536
- Original archive: https://news-web.php.net/php.internals/34536
- Started by Markus Fischer on 2008-01-06T19:37:40+00:00
- Messages: 5
- 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

---

## #34536 — Markus Fischer — 2008-01-06T19:37:40+00:00

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

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

accidentally I came across `settype()` in ext/standard/type.c which says

~  } else if (!strcasecmp(new_type, "float")) {
~    convert_to_double(*var);
~  } else if (!strcasecmp(new_type, "double")) { /* deprecated */
~    convert_to_double(*var);

This is the context of calling

~  settype($val, "double");

I don't understand the comment, because in `gettype()` there is

~  case IS_DOUBLE:
~    RETVAL_ASCII_STRING("double", 1);
~    break;

There's no possibility that `gettype()` returns "float", so maybe this
comment is just in the wrong line?

All in all a pretty superfluously mail but I thought I bring some
diversification in the type hint debate ;)

- - Markus
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHgS4E1nS0RcInK9ARArFQAKDBW9vqTA9QpA0LIVa/o18gZ1p0wACfQafo
KlyHR+2BYlk2Oj9B8KrQan4=
=vyS0
-----END PGP SIGNATURE

---

## #34538 — Hannes Magnusson — 2008-01-06T20:04:47+00:00

URL: https://externals.io/message/34536#34538 · In reply to: #34536

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi,
>
> accidentally I came across `settype()` in ext/standard/type.c which says
>
> ~  } else if (!strcasecmp(new_type, "float")) {
> ~    convert_to_double(*var);
> ~  } else if (!strcasecmp(new_type, "double")) { /* deprecated */
> ~    convert_to_double(*var);
>
> This is the context of calling
>
> ~  settype($val, "double");
>
> I don't understand the comment, because in `gettype()` there is
>
> ~  case IS_DOUBLE:
> ~    RETVAL_ASCII_STRING("double", 1);
> ~    break;
>
> There's no possibility that `gettype()` returns "float", so maybe this
> comment is just in the wrong line?

No, the comment is correct.

"for historical [read: BC] reasons "double" is returned in case of a
float, and not simply "float""

See http://docs.php.net/settype && http://docs.php.net/gettype

-Hannes

---

## #34540 — Markus Fischer — 2008-01-06T20:23:06+00:00

URL: https://externals.io/message/34536#34540 · In reply to: #34538

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Hannes Magnusson wrote:
| No, the comment is correct.
|
| "for historical [read: BC] reasons "double" is returned in case of a
| float, and not simply "float""
|
| See http://docs.php.net/settype && http://docs.php.net/gettype

Thanks for the pointers, but I don't quite understand what "deprecate"
now means.

Doing gettype(1.5) returns "double". There's not way that `gettype()`
returns "float".

I don't see the implications of this "deprecation" here. What does it
say? The comment in the sourceis there since around 2002 or so. But
there aren't plans to change the behavior or `gettype()`, are there?

Sorry if I seem nitpicking, I just got more confused after your mail :)

- - Markus
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHgTiq1nS0RcInK9ARAjkiAKDbBA66+XnNJ8RhgmdHHlonUW1MJgCg43wp
/YJJZkmsY1lqKV4lzfGoCxs=
=CQZj
-----END PGP SIGNATURE

---

## #34562 — Hannes Magnusson — 2008-01-06T22:30:48+00:00

URL: https://externals.io/message/34536#34562 · In reply to: #34540

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi,
>
> Hannes Magnusson wrote:
> | No, the comment is correct.
> |
> | "for historical [read: BC] reasons "double" is returned in case of a
> | float, and not simply "float""
> |
> | See http://docs.php.net/settype && http://docs.php.net/gettype
>
> Thanks for the pointers, but I don't quite understand what "deprecate"
> now means.

It means that maybe someday it will be removed. Unlikely? Sure, but
the preferred name is 'float' so why not use it?


> Doing gettype(1.5) returns "double". There's not way that `gettype()`
> returns "float".

Right. Due to historical reasons this functions returns 'double'.
Just like for historical reasons `implode()` can take its argument in
either order.


> I don't see the implications of this "deprecation" here. What does it
> say? The comment in the sourceis there since around 2002 or so. But
> there aren't plans to change the behavior or `gettype()`, are there?

It means that in PHP the type name is 'float' and referred to as
'float' throughout the manual
For convenience you can use "double" (is_double($f), (double)$f,
settype($f, "double")..), just like you can use `is_integer()` instead
of `is_int()`... :)


-Hannes

---

## #34563 — Markus Fischer — 2008-01-06T22:50:11+00:00

URL: https://externals.io/message/34536#34563 · In reply to: #34562

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Hannes Magnusson wrote:
| It means that in PHP the type name is 'float' and referred to as
| 'float' throughout the manual
| For convenience you can use "double" (is_double($f), (double)$f,
| settype($f, "double")..), just like you can use `is_integer()` instead
| of `is_int()`... :)

Ok, I got it. I think :)

So the manual says only float everywhere but throughout the source the
internal type (the #define) is DOUBLE and `gettype()` is also returns
"double". Basically, the manual says it's deprecated and documents it
different when in fact PHP actually doesn't implement it that way ...
Phew :)

- - Markus
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHgVsj1nS0RcInK9ARAqgsAJ0U/upO0t48xLWvvAjCqAs2RZOf7QCeIVK8
/JrmagWizxWsGK5C4PhY3s0=
=D7QP
-----END PGP SIGNATURE
