-
-
Notifications
You must be signed in to change notification settings - Fork 205
Open
Description
Related to #1589
Analysis
Recap of existing PHP 8.2 behavior based on the RFC:
class ReflectionProperty
{
// Signature 1: called with exactly 2 arguments.
public function setValue(object $object, mixed $value): void {}
// Signature 2: called with exactly 2 arguments (this is for static properties, where there is no $object).
public function setValue(mixed $unused, mixed $value): void {}
// Signature 3: called with exactly 1 argument.
public function setValue(mixed $value): void {}
}Updated behavior for each version:
class ReflectionProperty
{
// Signature 1: $object nullable in 8.3 (static properties set with null $object).
public function setValue(?object $object, mixed $value): void {}
// Signature 2: merged into signature 1, behavior unchanged
// Signature 3: deprecated in 8.3, removed in a future (TBD) major version.
}Note: we don't need to distinguish signatures 1 and 2 because they are merely merged and no behavior changes occurred.
Detection in PHP 8.2
(new ReflectionProperty(...))->setValue(...)with 1 or 2 arguments is valid.
Detection in PHP 8.3
(new ReflectionProperty(...))->setValue(...)with 1 argument is deprecated, add warning. See "Syntax Variations" below.
Syntax Variations
(new ReflectionProperty(...))->setValue(...)✅ Can be handled by PHPCompatibility.new ReflectionProperty(...)->setValue(...)✅ Can be handled by PHPCompatibility.$property = new ReflectionProperty(...); $property->setValue(...);🤷♀️ If they immediately follow each other, then maybe, but of limited value.$property->setValue(...);❌ Unreliable, as $property could be defined anywhere or reassigned before reaching this statement.
Top 2000
Found 7 occurrences of the deprecated signature in the top 2000 packages.
Example in roave/better-reflection:
$property = new ReflectionProperty($betterReflectionProperty);
if (! $property->isAccessible()) {
throw new CoreReflectionException(sprintf('Property "%s" is not accessible', $name));
}
if (! $property->isStatic()) {
throw new CoreReflectionException(sprintf('Property "%s" is not static', $name));
}
$property->setValue($value);3v4l.org
- ReflectionProperty::setValue - signature 3 deprecated in PHP >=8.3