php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #77034 Casting null to int undefined
Submitted: 2018-10-18 17:36 UTC Modified: 2018-10-19 13:34 UTC
From: casey dot mcginty at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Documentation problem
PHP Version: 7.2.11 OS:
Private report: No CVE-ID: None
 [2018-10-18 17:36 UTC] casey dot mcginty at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/language.types.integer
---

I do not see any documentation regarding a null cast to an int. What is the official behavior?

Test script:
---------------
$myInt = (int)null;


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-10-18 17:44 UTC] requinix@php.net
-Package: Documentation problem +Package: Variables related
 [2018-10-18 17:44 UTC] requinix@php.net
Are you actually asking that question or just implying you'd like the docs to say it?
 [2018-10-18 20:22 UTC] salathe@php.net
-Status: Open +Status: Not a bug
 [2018-10-18 20:22 UTC] salathe@php.net
See the section "Converting to integer" on the page you linked, particularly under the "From other types" subheading.
 [2018-10-18 20:43 UTC] requinix@php.net
But is casting null to integer really supposed to be undefined, or is it just that the doc doesn't mention null? The spec says it should be 0, which is the common sense answer.
https://github.com/php/php-langspec/blob/master/spec/08-conversions.md#user-content-converting-to-integer-type
 [2018-10-19 12:42 UTC] cmb@php.net
-Status: Not a bug +Status: Re-Opened -Package: Variables related +Package: Documentation problem -Assigned To: +Assigned To: cmb
 [2018-10-19 12:42 UTC] cmb@php.net
> But is casting null to integer really supposed to be undefined,
> or is it just that the doc doesn't mention null?

IMO, the latter.  Converting to string[1] explicitly mentions
the behavior of (string)NULL.

[1] <http://php.net/manual/en/language.types.string.php#language.types.string.casting>
 [2018-10-19 13:34 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=345850
Log: Fix #77034: Casting null to int undefined
 [2018-10-19 13:34 UTC] cmb@php.net
-Status: Re-Opened +Status: Closed
 [2018-10-19 13:34 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2020-02-07 06:05 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=ad6c4032099abf8dfc50b382bbd7800aac08f5a6
Log: Fix #77034: Casting null to int undefined
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 08:01:28 2024 UTC