From b0c295e5450985f035050449918a78b903af35d8 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 26 Apr 2020 08:15:37 -0700 Subject: [PATCH] Fix some PHP 7.4 array index access issues Summary: Ref T13518. See . Under PHP 7.4, accessing an array index of values like `false` and `null` is no longer valid. This is great, but we occasionally do it. Test Plan: - Upgraded to PHP 7.4. - Loaded revisions with added/changed lines, inlines, and Asana support configured. - Before patch: saw various fatals around accessing indexes of booleans and nulls. - After patch: clean revision. Maniphest Tasks: T13518 Differential Revision: https://secure.phabricator.com/D21172 --- .../customfield/DifferentialAsanaRepresentationField.php | 4 ++++ .../differential/parser/DifferentialChangesetParser.php | 6 ++++++ .../render/DifferentialChangesetTwoUpRenderer.php | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/src/applications/differential/customfield/DifferentialAsanaRepresentationField.php b/src/applications/differential/customfield/DifferentialAsanaRepresentationField.php index 266b410d4f..c584ef566f 100644 --- a/src/applications/differential/customfield/DifferentialAsanaRepresentationField.php +++ b/src/applications/differential/customfield/DifferentialAsanaRepresentationField.php @@ -44,6 +44,10 @@ final class DifferentialAsanaRepresentationField $edge = head($edges[$src_phid][$edge_type]); + if (!$edge) { + return null; + } + if (!empty($edge['data']['gone'])) { return phutil_tag( 'em', diff --git a/src/applications/differential/parser/DifferentialChangesetParser.php b/src/applications/differential/parser/DifferentialChangesetParser.php index 18217d7394..8cee8013a6 100644 --- a/src/applications/differential/parser/DifferentialChangesetParser.php +++ b/src/applications/differential/parser/DifferentialChangesetParser.php @@ -1326,9 +1326,15 @@ final class DifferentialChangesetParser extends Phobject { $old_back = array(); $new_back = array(); foreach ($this->old as $ii => $old) { + if ($old === null) { + continue; + } $old_back[$old['line']] = $old['line']; } foreach ($this->new as $ii => $new) { + if ($new === null) { + continue; + } $new_back[$new['line']] = $new['line']; } diff --git a/src/applications/differential/render/DifferentialChangesetTwoUpRenderer.php b/src/applications/differential/render/DifferentialChangesetTwoUpRenderer.php index a7af9333ff..3380e66c52 100644 --- a/src/applications/differential/render/DifferentialChangesetTwoUpRenderer.php +++ b/src/applications/differential/render/DifferentialChangesetTwoUpRenderer.php @@ -593,9 +593,14 @@ final class DifferentialChangesetTwoUpRenderer $map = array(); foreach ($new as $offset => $new_line) { + if ($new_line === null) { + continue; + } + if ($new_line['line'] === null) { continue; } + $map[$new_line['line']] = $offset; }