php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #21537 Need function parameters as entered
Submitted: 2003-01-08 22:04 UTC Modified: 2003-01-09 16:41 UTC
From: pmoulding at tedis dot com dot au Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 4.3.0 OS: inux, Solaris, NT, Win2000
Private report: No CVE-ID: None
 [2003-01-08 22:04 UTC] pmoulding at tedis dot com dot au
When I write a function as
xxx(1.0, 1.8);
The function receives 1 and 1.8, not 1.0 and 1.8. I tried get_func_arg() and other tricks but the 1.0 is converted to int(1) before it available for processing.

Could we have a language construct named:
get_func_arg_untouched_virginal_string_as_entered()
which keeps the parameter as a string?

I need to keep some numeric data in the original input format so it can be verified as typed and passed to other systems in the original format.

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-01-09 00:48 UTC] derick@php.net
You must be doing something else wrongly:

<?php
	function foo($a, $b) {
		var_dump ($a, $b);
	}

	foo(1.0, 1.8);
?>

[derick@kossu derick]$ php bug21537.php 
float(1)
float(1.8)


As you see it works fine...

Derick
 [2003-01-09 16:22 UTC] pmoulding at tedis dot com dot au
$a = 2.0;
$b = '2.0';
xxx($a, $b);
produces
2 2.0
2.0 is still converted to int(2) instead of float(2.0).

I need to know the exact input and thought the easiest way to check the input would be to get the input as an unconverted string.

In the example of 2.0, a float of 2.0 would tell me the type and accuracy. I would then get 3.10 as 3.10 instead of 3.1.

I have not tested floats with e notation or very long numbers. If someone types a long number, I want to detect the long number, recognise the number exceeds the accuracy of the default maths, and switch to arbitrary precision mathematics.

I do not want to tell the person using my function or class, a whole lot of rules about enclosing numbers in quotations when they contain certain values.
 [2003-01-09 16:41 UTC] zak@php.net
Hi Peter,  
  
One minor note here. The first argument is not converted  
to type integer. Rather, it is trimmed of non-numerically  
significant zeros.  
  
  function xxx($a,$b){  
	var_dump($a,$b);  
  }  
  xxx(2.0, "2.0");  
  
Outputs:  
  float(2)  
  string(3) "2.0"   
  
The type of the value is still float.  
  
This behaviour might be difficult to change, considering  
that it happens in all contexts - not just when formal  
parameters are passed to a function.  
  
$a = 2.0;  
var_dump($a);  
var_dump(2.0);  
  
Outputs:  
  float(2);  
  float(2);  
 
Cheers!  
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Aug 16 01:01:28 2024 UTC