Skip to content

"void" and "never" are not atomic types #5388

Open

Description

@MircoBabin

Affected page

https://www.php.net/manual/en/language.types.type-system.php

Current issue

Suggestion: Remove "void" and "never" from Built-in types and put them in a seperate list Return-only types, outside the Atomic types section. Because both are not atomic types like int, string etc.

Void

Currently void is listed as an atomic type.

  • But void is not a type at all. It is a keyword checked at compile time.
  • There is no comparison possible if a function returned void.
  • The RFC https://wiki.php.net/rfc/void_return_type also states the return value is null and not void.
function VoidIsNotAType() : void
{
}

$ret = VoidIsNotAType();
var_dump(VoidIsNotAType());
// NULL

// Comparison not possible, because VOID is not a type
// if ($ret !== void) echo 'Not void'."\n";
function UntypedVoidIsNotAType()
{
}

$ret = VoidIsNotAType();
var_dump(VoidIsNotAType());
// NULL

// Comparison not possible, because VOID is not a type
// if ($ret !== void) echo 'Not void'."\n";

Never

Currently never is listed as an atomic type.

  • But never is not a type at all. It is a keyword checked at compile time.
  • The RFC https://wiki.php.net/rfc/noreturn_type states Both noreturn and void are both only valid as return types, but there the similarity ends.

Suggested improvement

...

Additional context (optional)

...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions