php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #67837 Allow "numeric" type cast and declaration
Submitted: 2014-08-13 18:52 UTC Modified: 2018-11-20 19:59 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: lkmorlan at uwaterloo dot ca Assigned:
Status: Suspended Package: Scripting Engine problem
PHP Version: 7.x OS: all
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2014-08-13 18:52 UTC] lkmorlan at uwaterloo dot ca
Description:
------------
It would be useful to have the ability to cast to (number), which would cast to either (int) or (float), as needed.

(number) $var;
Would be the same as:
$var += 0;


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-14 05:49 UTC] datibbaw@php.net
Alternatively, you can currently accomplish this with a unary +:

  $number = +$var;
 [2018-09-09 00:52 UTC] carusogabriel@php.net
A `number` cast would be useful to convert, for example, binary bases, which today isn't possible using `+`, `(int)` or `(float)` before the variable: https://3v4l.org/kspcM
 [2018-10-01 12:17 UTC] cmb@php.net
-Status: Open +Status: Suspended -Package: Variables related +Package: Scripting Engine problem
 [2018-10-01 12:17 UTC] cmb@php.net
A former RFC[1] reserved the word “numeric”, so it would be more
reasonable to use this instead of “number”.  However, I feel that
a type cast which is not also allowed as type declaration is
somewhat strange.  Anyhow, this feature request certainly requires
discussion on internals@ and likely the RFC process[2].  Feel free
to start it.  For the time being, I'm suspending this ticket.

[1] <https://wiki.php.net/rfc/reserve_even_more_types_in_php_7>
[2] <https://wiki.php.net/rfc/howto>
 [2018-11-20 19:59 UTC] lkmorlan at uwaterloo dot ca
-Summary: Allow cast to (number) +Summary: Allow "numeric" type cast and declaration -PHP Version: 5.6.0RC3 +PHP Version: 7.x
 [2018-11-20 19:59 UTC] lkmorlan at uwaterloo dot ca
I'm fine with "numeric" and I agree about the declaration.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Jul 24 02:01:27 2019 UTC