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

php.internals

Markus Fischer

18 years ago
-----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-----

Hannes Magnusson

18 years ago
On Jan 6, 2008 8:37 PM, Markus Fischer <markus@fischer.name> wrote:
> -----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

Markus Fischer

18 years ago
-----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-----

Hannes Magnusson

18 years ago
On Jan 6, 2008 9:23 PM, Markus Fischer <markus@fischer.name> wrote:
> -----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

Markus Fischer

18 years ago
-----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-----