PHPStan: PHP 8.4 Cannot unset property Drupal\views\ViewExecutable::$row_index because it might have hooks in a subclass.
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3543372. --> Reported by: [joelpittet](https://www.drupal.org/user/160302) Related to !66 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>PHPStan flags an error in <code>src/Plugin/views/style/Calendar.php</code> (line ~697): unsetting <code>Drupal\views\ViewExecutable::$row_index</code> triggers rule <code>unset.possiblyHookedProperty</code>. This breaks static analysis/CI.</p> <h4 id="summary-steps-reproduce">Steps to reproduce</h4> <ol> <li>Install/enable the Calendar module.</li> <li>Run PHPStan on the module, e.g. <code>ddev phpstan</code>.</li> <li>Observe the reported error about <code>unset($this-&gt;view-&gt;row_index)</code>.</li> </ol> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>Replace the <code>unset</code> of the object property with a safe assignment, avoiding magic <code>__unset()</code> hooks.</p> <div class="codeblock"> <pre><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br></span><span style="color: #FF8000">// Before<br></span><span style="color: #007700">unset(</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">view</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">row_index</span><span style="color: #007700">);<br><br></span><span style="color: #FF8000">// After<br></span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">view</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">row_index </span><span style="color: #007700">= </span><span style="color: #0000BB">null</span><span style="color: #007700">; </span><span style="color: #FF8000">// Clear without invoking __unset hooks<br></span><span style="color: #0000BB">?&gt;</span></span></pre></div> <p>Rationale: PHPStan Drupal rule disallows unsetting object properties that may be hooked in subclasses. Setting to <code>null</code> preserves intent without side effects.</p> <h3 id="summary-remaining-tasks">Remaining tasks</h3> <ul> <li>Apply the change and re-run PHPStan to confirm the error is resolved.</li> <li>Search for and fix any similar <code>unset()</code> calls on object properties in the module.</li> <li>Smoke-test Views rendering to ensure no behavioural regressions.</li> </ul>
issue