Skip to content

A "never" function is checked at compile time and runtime, and may still throw #5390

@MircoBabin

Description

@MircoBabin

Affected page

https://www.php.net/manual/en/language.types.never.php

Current issue

  • There is no mention that a "never" function is checked by the compiler. And that the check is that no "return;" is used.
  • There is no mention that a "never" function can produce a TypeError at runtime.
  • There is no mention that a "never" function can still throw an Exception.
  • There is no mention that "never" is not a type, but only a return-only type.

Suggested improvement

Mention these points.

Additional context (optional)

  • Never can throw a TypeError at runtime:
// Simulate auto loading
$php = 
<<<'EOD'
    class Unknown
    {
        public static function Nothing()
        {
        }
    }
EOD;
eval($php);

function NeverReturns() : never
{
    Unknown::Nothing();
    // exit;
}

NeverReturns();

// Fatal error: Uncaught TypeError: NeverReturns(): never-returning function must not implicitly return in /in/GMMAC:19
// Stack trace:
// #0 /in/GMMAC(21): NeverReturns()
// #1 {main}
//  thrown in /in/GMMAC on line 19

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