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