Skip to content

False positive: Always throwing and returning never #15070

Open

Description

@uuf6429

Bug report

Given the following...

<?php

final class Url
{
	public function __clone(): never // <<
	{
		throw new \BadMethodCallException('Always throw');
	}
}

final class Email
{
	/**
	 * @return never
	 */
	public function __clone(): never
	{
		throw new \BadMethodCallException('Always throw');
	}
}

...PHPStan warns (on line 5) that a method that throws unconditionally should have the never return type (which it already does).

Originally, I had code returning void, but I never saw that warning in our code, it only showed up in the playground when I happened to paste my code for trying something else. Interestingly, the error identifier is phpstanPlayground.never. Also interesting that the PHPDoc one works.

Code snippet that reproduces the problem

https://phpstan.org/r/4670249c-9af0-4d1a-bcc2-c583c449dd46

Expected output

I didn't expect the error.

Did PHPStan help you today? Did it make you happy in any way?

Always :)

Activity

  1. added this to the Easy fixes milestone on Aug 11, 2026
  2. staabm commented on Aug 11, 2026

    @staabm
    Contributor

    note: public function __clone(): never is a fatal error on PHP < 8.1

    https://3v4l.org/2WDCe#veol

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

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions