Skip to content

Commit 6136964

Browse files
author
epriestley
committed
Fix a PHP 8.1 strlen() issue with "mysql.pass" configuration
Summary: Ref T13588. This configuration value may not be set. Also fix an issue in `bin/storage` and whatever else I hit between now and this diff actually uploading. Also fix a MySQLi report mode difference, beginning in PHP 8.1. Also update a bunch of "static" property usage in Lisk. Test Plan: Ran `bin/files ...` locally under PHP 8.1. Maniphest Tasks: T13588 Differential Revision: https://secure.phabricator.com/D21744
1 parent dc705ce commit 6136964

File tree

13 files changed

+81
-60
lines changed

13 files changed

+81
-60
lines changed

.arclint

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@
7979
"xhpast": {
8080
"type": "xhpast",
8181
"include": "(\\.php$)",
82-
"standard": "phutil.xhpast"
82+
"standard": "phutil.xhpast",
83+
"xhpast.php-version": "5.5"
8384
}
8485
}
8586
}

scripts/sql/manage_storage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595

9696
$host = $args->getArg('host');
9797
$ref_key = $args->getArg('ref');
98-
if (strlen($host) || strlen($ref_key)) {
98+
if (($host !== null) || ($ref_key !== null)) {
9999
if ($host && $ref_key) {
100100
throw new PhutilArgumentUsageException(
101101
pht(

src/applications/files/engine/PhabricatorLocalDiskFileStorageEngine.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function getEnginePriority() {
2626

2727
public function canWriteFiles() {
2828
$path = PhabricatorEnv::getEnvConfig('storage.local-disk.path');
29+
$path = phutil_string_cast($path);
2930
return (bool)strlen($path);
3031
}
3132

src/applications/meta/query/PhabricatorApplicationQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected function loadPage() {
8989
}
9090
}
9191

92-
if (strlen($this->nameContains)) {
92+
if ($this->nameContains !== null) {
9393
foreach ($apps as $key => $app) {
9494
if (stripos($app->getName(), $this->nameContains) === false) {
9595
unset($apps[$key]);

src/applications/people/query/PhabricatorPeopleQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
341341
(int)$this->isMailingList);
342342
}
343343

344-
if (strlen($this->nameLike)) {
344+
if ($this->nameLike !== null) {
345345
$where[] = qsprintf(
346346
$conn,
347347
'user.username LIKE %~ OR user.realname LIKE %~',

src/applications/people/storage/PhabricatorUser.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ public function save() {
275275
$this->setConduitCertificate($this->generateConduitCertificate());
276276
}
277277

278-
if (!strlen($this->getAccountSecret())) {
278+
$secret = $this->getAccountSecret();
279+
if (($secret === null) || !strlen($secret)) {
279280
$this->setAccountSecret(Filesystem::readRandomCharacters(64));
280281
}
281282

src/applications/phid/handle/pool/PhabricatorHandleList.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,27 @@ public function renderHandle($phid) {
126126
/* -( Iterator )----------------------------------------------------------- */
127127

128128

129+
#[\ReturnTypeWillChange]
129130
public function rewind() {
130131
$this->cursor = 0;
131132
}
132133

134+
#[\ReturnTypeWillChange]
133135
public function current() {
134136
return $this->getHandle($this->phids[$this->cursor]);
135137
}
136138

139+
#[\ReturnTypeWillChange]
137140
public function key() {
138141
return $this->phids[$this->cursor];
139142
}
140143

144+
#[\ReturnTypeWillChange]
141145
public function next() {
142146
++$this->cursor;
143147
}
144148

149+
#[\ReturnTypeWillChange]
145150
public function valid() {
146151
return ($this->cursor < $this->count);
147152
}
@@ -150,6 +155,7 @@ public function valid() {
150155
/* -( ArrayAccess )-------------------------------------------------------- */
151156

152157

158+
#[\ReturnTypeWillChange]
153159
public function offsetExists($offset) {
154160
// NOTE: We're intentionally not loading handles here so that isset()
155161
// checks do not trigger fetches. This gives us better bulk loading
@@ -162,17 +168,20 @@ public function offsetExists($offset) {
162168
return isset($this->map[$offset]);
163169
}
164170

171+
#[\ReturnTypeWillChange]
165172
public function offsetGet($offset) {
166173
if ($this->handles === null) {
167174
$this->loadHandles();
168175
}
169176
return $this->handles[$offset];
170177
}
171178

179+
#[\ReturnTypeWillChange]
172180
public function offsetSet($offset, $value) {
173181
$this->raiseImmutableException();
174182
}
175183

184+
#[\ReturnTypeWillChange]
176185
public function offsetUnset($offset) {
177186
$this->raiseImmutableException();
178187
}
@@ -189,6 +198,7 @@ private function raiseImmutableException() {
189198
/* -( Countable )---------------------------------------------------------- */
190199

191200

201+
#[\ReturnTypeWillChange]
192202
public function count() {
193203
return $this->count;
194204
}

src/infrastructure/cluster/PhabricatorDatabaseRef.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ public static function newRefs() {
322322
$default_user = PhabricatorEnv::getEnvConfig('mysql.user');
323323

324324
$default_pass = PhabricatorEnv::getEnvConfig('mysql.pass');
325+
$default_pass = phutil_string_cast($default_pass);
325326
$default_pass = new PhutilOpaqueEnvelope($default_pass);
326327

327328
$config = PhabricatorEnv::getEnvConfig('cluster.databases');

src/infrastructure/query/PhabricatorQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private function flattenSubclause(array $parts) {
8787
foreach ($this->flattenSubclause($part) as $subpart) {
8888
$result[] = $subpart;
8989
}
90-
} else if (strlen($part)) {
90+
} else if (($part !== null) && strlen($part)) {
9191
$result[] = $part;
9292
}
9393
}

src/infrastructure/storage/connection/mysql/AphrontMySQLiDatabaseConnection.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ protected function connect() {
5757
}
5858
}
5959

60+
// See T13588. In PHP 8.1, the default "report mode" for MySQLi has
61+
// changed, which causes MySQLi to raise exceptions. Disable exceptions
62+
// to align behavior with older default behavior under MySQLi, which
63+
// this code expects. Plausibly, this code could be updated to use
64+
// MySQLi exceptions to handle errors under a wider range of PHP versions.
65+
mysqli_report(MYSQLI_REPORT_OFF);
66+
6067
$conn = mysqli_init();
6168

6269
$timeout = $this->getConfiguration('timeout');

0 commit comments

Comments
 (0)