Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F3388774
D25945.1744448273.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
2 KB
Referenced Files
None
Subscribers
None
D25945.1744448273.diff
View Options
diff --git a/src/applications/diffusion/conduit/DiffusionBranchQueryConduitAPIMethod.php b/src/applications/diffusion/conduit/DiffusionBranchQueryConduitAPIMethod.php
--- a/src/applications/diffusion/conduit/DiffusionBranchQueryConduitAPIMethod.php
+++ b/src/applications/diffusion/conduit/DiffusionBranchQueryConduitAPIMethod.php
@@ -56,7 +56,7 @@
$refs = array();
foreach ($ref_map as $ref => $commit) {
$refs[] = id(new DiffusionRepositoryRef())
- ->setShortName($ref)
+ ->setShortName((string)$ref)
->setCommitIdentifier($commit);
}
} else {
diff --git a/src/applications/diffusion/data/DiffusionGitBranch.php b/src/applications/diffusion/data/DiffusionGitBranch.php
--- a/src/applications/diffusion/data/DiffusionGitBranch.php
+++ b/src/applications/diffusion/data/DiffusionGitBranch.php
@@ -101,7 +101,9 @@
if ($branch == '(no branch)') {
continue;
}
-
+ // Note: If the $branch name string is numeric containing only decimal
+ // ints and does not start with 0, PHP will cast it from string to int:
+ // https://www.php.net/manual/en/language.types.array.php#language.types.array.syntax
$map[$branch] = $branch_head;
}
diff --git a/src/docs/flavor/php_pitfalls.diviner b/src/docs/flavor/php_pitfalls.diviner
--- a/src/docs/flavor/php_pitfalls.diviner
+++ b/src/docs/flavor/php_pitfalls.diviner
@@ -374,3 +374,25 @@
// ...
}
```
+
+= PHP casts all-digit array keys from string to int =
+
+An array key which is a string that contains a decimal int will be cast to the
+int type:
+
+```lang=php
+$key0 = "main";
+$key1 = "123";
+$key2 = "0123";
+$array = array($key0 => "foo", $key1 => "foo", $key2 => "foo");
+foreach ($array as $key => $value) {
+ print(gettype($key)."\n");
+}
+```
+prints `string`, `integer`, `string`.
+
+Thus running `phutil_nonempty_string($key)` complains that it expected null or
+a string but got int.
+
+Avoid this by either explicitly casting via `(string)$key`, or by using
+`phutil_nonempty_scalar($key)` instead of `phutil_nonempty_string($key)`.
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Apr 12, 08:57 (1 w, 23 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1274674
Default Alt Text
D25945.1744448273.diff (2 KB)
Attached To
Mode
D25945: Fix exception handling a numeric git branch ("Call to phutil_nonempty_string() expected null or a string, got: int" in PhabricatorRepository)
Attached
Detach File
Event Timeline
Log In to Comment