Re: [Question] behavior of `null + null = 0`

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


On 04/09/2023 05:35, tyamahori wrote:
Dear PHP users.

I have questions about the behavior `null + null = 0`.

Since PHP4.3.0, `null + null` becomes `0`.

Form php-src,

It seems _zendi_try_convert_scalar_to_number converts null to 0.

Do you know who decided this behavior ?
Do you know how did this behavior come about?


What you're looking at here is type coercian, or as PHP refers to it, type juggling.

You're using a non-numerica type as a number when you use the + operator. This has the effect of casting null first to an int, which results in your calculation becoming 0 + 0.

More details on PHPs type juggling can be found at



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux