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


Add a Patch

Pull Requests

Add a Pull Request


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

  $number = +$var;
 [2018-09-09 00:52 UTC]
A `number` cast would be useful to convert, for example, binary bases, which today isn't possible using `+`, `(int)` or `(float)` before the variable:
 [2018-10-01 12:17 UTC]
-Status: Open +Status: Suspended -Package: Variables related +Package: Scripting Engine problem
 [2018-10-01 12:17 UTC]
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] <>
[2] <>
 [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: Thu Aug 22 22:01:27 2019 UTC