Skip to content

Commit c019c75

Browse files
committed
PHP 8.5 | File::getMemberProperties(): fix "Using null as an array offset" deprecation
If a variable in the global scope is passed to `File::getMemberProperties()`, the token may not have any "conditions". This would result in `array_keys()` returning an empty array, which will cause `array_pop()` to return `null`, leading to the deprecation notice. Fixed now via some extra defensive coding. This change is already covered via the existing tests. Ref: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_using_values_null_as_an_array_offset_and_when_calling_array_key_exists
1 parent f1c9394 commit c019c75

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/Files/File.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,6 +1876,10 @@ public function getMemberProperties($stackPtr)
18761876
throw new RuntimeException('$stackPtr must be of type T_VARIABLE');
18771877
}
18781878

1879+
if (empty($this->tokens[$stackPtr]['conditions']) === true) {
1880+
throw new RuntimeException('$stackPtr is not a class member var');
1881+
}
1882+
18791883
$conditions = array_keys($this->tokens[$stackPtr]['conditions']);
18801884
$ptr = array_pop($conditions);
18811885
if (isset($this->tokens[$ptr]) === false

0 commit comments

Comments
 (0)