🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

Detect wrong type used with new #4922

Description

@johnbillion

Feature request

Similarly to detecting the wrong type passed to a function parameter, it would be great if PHPStan could detect the type used with new to ensure it's always valid, so any problems can be caught before runtime.

Acceptable types for new appear to be:

  • string (preferably class-string)
  • static keyword
  • self keyword
  • parent keyword

For example, the following should raise an error:

function get_class_name() : int {
	return 123;
}

$class = get_class_name();

new $class;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions