Feature Request
Downgrading from PHP 8.2 to 8.1 currently leaves memory_reset_peak_usage() untouched, so the resulting code fatals on < 8.2 (Call to undefined function). I'd like to add a downgrade rule for it, but unlike array_is_list() / json_validate() / stream_isatty() this function cannot be polyfilled: it resets the engine's internal memory peak counter, and there is no userland API to do that before 8.2. Any downgrade therefore silently drops the semantics (a later memory_get_peak_usage() returns the non-reset peak). Because that's a behavior/policy question, I'd like maintainer guidance before implementing.
Option A — function_exists() guard, no-op fallback
-memory_reset_peak_usage();
+if (function_exists('memory_reset_peak_usage')) {
+ memory_reset_peak_usage();
+}
Runs on 8.2+, no-op on older PHP. Consistent with the existing function_exists idiom, but silently loses the peak reset. Simpler than the polyfill rules — the function is void and takes no arguments, so no closure/snippet is needed, just the guard.
Option B — don't add a rule
Leave the call as-is. The function is purely diagnostic/profiling, so arguably it's more honest to let the developer decide than to silently change memory-monitoring behavior.
Question
Would you accept Option A, prefer no rule, or have another shape in mind? Happy to open the PR once the direction is clear.
For reference, the semantically-clean sibling case ReflectionMethod::hasPrototype() (also 8.2, but polyfillable via getPrototype() + try/catch) is already up as rectorphp/rector-downgrade-php#398.
Feature Request
Downgrading from PHP 8.2 to 8.1 currently leaves
memory_reset_peak_usage()untouched, so the resulting code fatals on < 8.2 (Call to undefined function). I'd like to add a downgrade rule for it, but unlikearray_is_list()/json_validate()/stream_isatty()this function cannot be polyfilled: it resets the engine's internal memory peak counter, and there is no userland API to do that before 8.2. Any downgrade therefore silently drops the semantics (a latermemory_get_peak_usage()returns the non-reset peak). Because that's a behavior/policy question, I'd like maintainer guidance before implementing.Option A —
function_exists()guard, no-op fallbackRuns on 8.2+, no-op on older PHP. Consistent with the existing
function_existsidiom, but silently loses the peak reset. Simpler than the polyfill rules — the function isvoidand takes no arguments, so no closure/snippet is needed, just the guard.Option B — don't add a rule
Leave the call as-is. The function is purely diagnostic/profiling, so arguably it's more honest to let the developer decide than to silently change memory-monitoring behavior.
Question
Would you accept Option A, prefer no rule, or have another shape in mind? Happy to open the PR once the direction is clear.
For reference, the semantically-clean sibling case
ReflectionMethod::hasPrototype()(also 8.2, but polyfillable viagetPrototype()+ try/catch) is already up as rectorphp/rector-downgrade-php#398.