Skip to content

NativeFunctionReflection does not allow identifying core functions as being deprecated #5373

@mglaman

Description

@mglaman

Bug report

While working on #5368, I realized that deprecated core functions were not being flagged, like create_function which was deprecated in 7.2 and removed 8.0.

However, NativeFunctionReflection hardcodes isDeprecated to always be "no".

	public function getDeprecatedDescription(): ?string
	{
		return null;
	}

	public function isDeprecated(): TrinaryLogic
	{
		return TrinaryLogic::createNo();
	}

These values can be parsed via the PhpStorm stubs, which are documented using PHP attributes, now

#[Deprecated(reason: "Use anonymous functions instead", since: "7.2")]
function create_function (string $args, string $code): false|string
{}

Screen Shot 2021-07-23 at 3 48 19 PM

Stub examples

https://github.com/JetBrains/phpstorm-stubs/blob/5cae90f74aa33a4cdbeb4da654525fe665e735c9/Core/Core.php

/**
 * Create an anonymous (lambda-style) function
 * @link https://php.net/manual/en/function.create-function.php
 * @param string $args <p>
 * The function arguments.
 * </p>
 * @param string $code <p>
 * The function code.
 * </p>
 * @return string|false a unique function name as a string, or false on error.
 * @removed 8.0
 */
#[Deprecated(reason: "Use anonymous functions instead", since: "7.2")]
function create_function(string $args, string $code): false|string {}

https://github.com/JetBrains/phpstorm-stubs/blob/v2019.3/Core/Core.php

/**
 * Create an anonymous (lambda-style) function
 * @link https://php.net/manual/en/function.create-function.php
 * @param string $args <p>
 * The function arguments.
 * </p>
 * @param string $code <p>
 * The function code.
 * </p>
 * @return string a unique function name as a string, or false on error.
 * @since 4.0.1
 * @since 5.0
 * @deprecated 7.2 Use anonymous functions instead.
 */
function create_function ($args, $code) {}

Code snippet that reproduces the problem

https://phpstan.org/r/7b7db20f-8b1d-411d-9d9e-41dbec9bae4d

Expected output

I would expected phpstan/phpstan-deprecation-rules to flag and identify this.

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