-
-
Notifications
You must be signed in to change notification settings - Fork 737
Closed
rectorphp/rector-src
#7095Labels
Description
Bug Report
Hello!
When an array access is in an isset, changing to a method call breaks the application:
| Subject | Details |
|---|---|
| Rector version | last dev-main |
| Installed as | composer dependency |
Minimal PHP Code Causing Issue
See https://getrector.com/demo/ca9a0b4d-9941-4412-8c66-a3fca9ca4593
<?php
class Model implements ArrayAccess
{
public function getAttribute(string $attribute): mixed {}
}
final class DemoFile
{
public function run(Model $model): void
{
if (isset($model['id'])) {
unset($model['id']);
}
}
}should probably be:
<?php
class Model implements ArrayAccess
{
public function getAttribute(string $attribute): mixed {}
}
final class DemoFile
{
public function run(Model $model): void
{
if ($model->getAttribute('id') !== null) {
$model->offsetUnset('id');
}
}
}Responsible rules
ArrayDimFetchToMethodCallRector
Expected Behavior
I would expect either:
- the array access not to be updated
- or the
issetto be removed and replaced with$model->getAttribute(...) !== null
Additionally, when replacing array access that inside an unset, the ArrayAccess offsetUnset is no longer called for method calls---I'm not really sure what the behaviour should be in this case---it should probably be updated to call offsetUnset directly instead of the configured method