Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F3479757
D25945.1744765114.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.1744765114.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
@@ -80,7 +80,10 @@
}
/**
- * As above, but with no `-r`. Used for bare repositories.
+ * Parse the output of 'git branch --verbose --no-abbrev' or similar into a
+ * map. As parseRemoteBranchOutput but no `-r`. Used for bare repositories.
+ *
+ * @return map Map of branch name (string or int) and its hash (string).
*/
public static function parseLocalBranchOutput($stdout) {
$map = array();
@@ -101,7 +104,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
Wed, Apr 16, 00:58 (5 h, 34 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1272497
Default Alt Text
D25945.1744765114.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