[PHP] Re: changing NULL behavior in PHP arithmetic

2010-04-16 Thread cr.vegelin


- Original Message - 
From: "Shawn McKenzie" 

To: 
Cc: 
Sent: Saturday, April 17, 2010 3:41 AM
Subject: Re: changing NULL behavior in PHP arithmetic



On 04/15/2010 02:46 AM, cr.vege...@gmail.com wrote:

Hi All,

Is there an option in PHP to change the behavior of NULL in PHP functions 
?

Now PHP uses NULL as a 0 (zero) for arithmetic, for example:
NULL + 6 = 6
NULL * 6 = 0
NULL / 6 = 0
6 / NULL = Division by zero

What I need is the same behavior as #N/A (or =NA()) in Excel, where:
#N/A + 6 = #N/A
#N/A * 6 = #N/A
#N/A / 6 = #N/A
6 / #N/A = #N/A

because arithmetic operations with "Unknown" operands should result to 
"Unknown" ...


TIA, Cor



In what cases do you have a null var?



Hi Shawn,

I am dealing with time series.
As an example, assume rows per year with 12 monthly values.
For 2009 all values are known, and numeric.
For 2010 some values are known, some are unknown.
The 2009 total can be calculated, but the 2010 total should be unknown,
and should not be the sum of the known values.

Thanks, Cor






--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: changing NULL behavior in PHP arithmetic

2010-04-16 Thread Shawn McKenzie
On 04/15/2010 02:46 AM, cr.vege...@gmail.com wrote:
> Hi All,
> 
> Is there an option in PHP to change the behavior of NULL in PHP functions ?
> Now PHP uses NULL as a 0 (zero) for arithmetic, for example:
> NULL + 6 = 6
> NULL * 6 = 0
> NULL / 6 = 0
> 6 / NULL = Division by zero
> 
> What I need is the same behavior as #N/A (or =NA()) in Excel, where:
> #N/A + 6 = #N/A
> #N/A * 6 = #N/A
> #N/A / 6 = #N/A
> 6 / #N/A = #N/A
> 
> because arithmetic operations with "Unknown" operands should result to 
> "Unknown" ...
> 
> TIA, Cor
> 

In what cases do you have a null var?

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php