1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Reflection;
4:
5: use PHPStan\TrinaryLogic;
6: use PHPStan\Type\Type;
7:
8: /**
9: * Reflection for a standalone function (not a class method).
10: *
11: * Represents both built-in PHP functions and user-defined functions. Like methods,
12: * functions can have multiple "variants" (overloaded signatures) — particularly
13: * common for built-in functions where the return type depends on argument types.
14: *
15: * Extension developers encounter this interface when implementing
16: * DynamicFunctionReturnTypeExtension or FunctionTypeSpecifyingExtension.
17: *
18: * Functions referenced in Scope::getFunctionCallStack() may be either
19: * FunctionReflection or MethodReflection.
20: *
21: * @api
22: * @api-do-not-implement
23: */
24: interface FunctionReflection
25: {
26:
27: public function getName(): string;
28:
29: public function getFileName(): ?string;
30:
31: /** @return list<ExtendedParametersAcceptor> */
32: public function getVariants(): array;
33:
34: /** @internal */
35: public function getOnlyVariant(): ExtendedParametersAcceptor;
36:
37: /**
38: * Returns alternative signatures used when the function is called with named arguments.
39: * Returns null if the named argument variants are the same as regular variants.
40: *
41: * @return list<ExtendedParametersAcceptor>|null
42: */
43: public function getNamedArgumentsVariants(): ?array;
44:
45: public function acceptsNamedArguments(): TrinaryLogic;
46:
47: public function isDeprecated(): TrinaryLogic;
48:
49: public function getDeprecatedDescription(): ?string;
50:
51: public function isInternal(): TrinaryLogic;
52:
53: public function getThrowType(): ?Type;
54:
55: public function hasSideEffects(): TrinaryLogic;
56:
57: public function isBuiltin(): bool;
58:
59: public function getAsserts(): Assertions;
60:
61: public function getDocComment(): ?string;
62:
63: public function returnsByReference(): TrinaryLogic;
64:
65: /**
66: * In most cases hasSideEffects() is more practical as it also accounts
67: * for void return type (functions returning void are always impure).
68: */
69: public function isPure(): TrinaryLogic;
70:
71: /** @return list<AttributeReflection> */
72: public function getAttributes(): array;
73:
74: /**
75: * On PHP 8.5+ if the return value is unused at runtime, a warning is emitted.
76: * PHPStan reports this during analysis regardless of PHP version.
77: */
78: public function mustUseReturnValue(): TrinaryLogic;
79:
80: }
81: