Skip to content

Commit 17ab000

Browse files
authored
Merge pull request #956 from WordPress/feature/php-8.5-fix-using-null-as-array-offset-notices
2 parents 8d4b418 + fa387d2 commit 17ab000

File tree

3 files changed

+37
-19
lines changed

3 files changed

+37
-19
lines changed

src/Iri.php

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public function __get($name) {
216216
$return = null;
217217
}
218218

219-
if ($return === null && isset($this->normalization[$this->scheme][$name])) {
219+
if ($return === null && isset($this->scheme, $this->normalization[$this->scheme][$name])) {
220220
return $this->normalization[$this->scheme][$name];
221221
}
222222
else {
@@ -671,27 +671,29 @@ protected function remove_iunreserved_percent_encoded($regex_match) {
671671
}
672672

673673
protected function scheme_normalization() {
674-
if (isset($this->normalization[$this->scheme]['iuserinfo']) && $this->iuserinfo === $this->normalization[$this->scheme]['iuserinfo']) {
675-
$this->iuserinfo = null;
676-
}
677-
if (isset($this->normalization[$this->scheme]['ihost']) && $this->ihost === $this->normalization[$this->scheme]['ihost']) {
678-
$this->ihost = null;
679-
}
680-
if (isset($this->normalization[$this->scheme]['port']) && $this->port === $this->normalization[$this->scheme]['port']) {
681-
$this->port = null;
682-
}
683-
if (isset($this->normalization[$this->scheme]['ipath']) && $this->ipath === $this->normalization[$this->scheme]['ipath']) {
684-
$this->ipath = '';
674+
if (isset($this->scheme, $this->normalization[$this->scheme])) {
675+
if (isset($this->normalization[$this->scheme]['iuserinfo']) && $this->iuserinfo === $this->normalization[$this->scheme]['iuserinfo']) {
676+
$this->iuserinfo = null;
677+
}
678+
if (isset($this->normalization[$this->scheme]['ihost']) && $this->ihost === $this->normalization[$this->scheme]['ihost']) {
679+
$this->ihost = null;
680+
}
681+
if (isset($this->normalization[$this->scheme]['port']) && $this->port === $this->normalization[$this->scheme]['port']) {
682+
$this->port = null;
683+
}
684+
if (isset($this->normalization[$this->scheme]['ipath']) && $this->ipath === $this->normalization[$this->scheme]['ipath']) {
685+
$this->ipath = '';
686+
}
687+
if (isset($this->normalization[$this->scheme]['iquery']) && $this->iquery === $this->normalization[$this->scheme]['iquery']) {
688+
$this->iquery = null;
689+
}
690+
if (isset($this->normalization[$this->scheme]['ifragment']) && $this->ifragment === $this->normalization[$this->scheme]['ifragment']) {
691+
$this->ifragment = null;
692+
}
685693
}
686694
if (isset($this->ihost) && empty($this->ipath)) {
687695
$this->ipath = '/';
688696
}
689-
if (isset($this->normalization[$this->scheme]['iquery']) && $this->iquery === $this->normalization[$this->scheme]['iquery']) {
690-
$this->iquery = null;
691-
}
692-
if (isset($this->normalization[$this->scheme]['ifragment']) && $this->ifragment === $this->normalization[$this->scheme]['ifragment']) {
693-
$this->ifragment = null;
694-
}
695697
}
696698

697699
/**

src/Response/Headers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function offsetGet($offset) {
3737
$offset = strtolower($offset);
3838
}
3939

40-
if (!isset($this->data[$offset])) {
40+
if (!isset($offset, $this->data[$offset])) {
4141
return null;
4242
}
4343

src/Utility/CaseInsensitiveDictionary.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ public function offsetExists($offset) {
5151
$offset = strtolower($offset);
5252
}
5353

54+
if ($offset === null) {
55+
$offset = '';
56+
}
57+
5458
return isset($this->data[$offset]);
5559
}
5660

@@ -66,6 +70,10 @@ public function offsetGet($offset) {
6670
$offset = strtolower($offset);
6771
}
6872

73+
if ($offset === null) {
74+
$offset = '';
75+
}
76+
6977
if (!isset($this->data[$offset])) {
7078
return null;
7179
}
@@ -91,6 +99,10 @@ public function offsetSet($offset, $value) {
9199
$offset = strtolower($offset);
92100
}
93101

102+
if ($offset === null) {
103+
$offset = '';
104+
}
105+
94106
$this->data[$offset] = $value;
95107
}
96108

@@ -105,6 +117,10 @@ public function offsetUnset($offset) {
105117
$offset = strtolower($offset);
106118
}
107119

120+
if ($offset === null) {
121+
$offset = '';
122+
}
123+
108124
unset($this->data[$offset]);
109125
}
110126

0 commit comments

Comments
 (0)