From 2a0e947acb8f18b4e83ee77e27df91cbc5802774 Mon Sep 17 00:00:00 2001 From: Marco van 't Wout Date: Wed, 27 Sep 2023 15:57:28 +0200 Subject: [PATCH 1/3] REFACTOR: port various php compatibility fixes from https://github.com/pear/Text_Diff/ master@4905970 --- framework/gii/components/Pear/Text/Diff.php | 4 +--- framework/gii/components/Pear/Text/Diff/Engine/native.php | 5 +++-- framework/gii/components/Pear/Text/Diff/Mapped.php | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/framework/gii/components/Pear/Text/Diff.php b/framework/gii/components/Pear/Text/Diff.php index 2e55623bcd..add8c114b4 100644 --- a/framework/gii/components/Pear/Text/Diff.php +++ b/framework/gii/components/Pear/Text/Diff.php @@ -216,14 +216,12 @@ static function trimNewlines(&$line, $key) /** * Determines the location of the system temporary directory. * - * @static - * * @access protected * * @return string A directory name which can be used for temp files. * Returns false if one could not be found. */ - function _getTempDir() + static function _getTempDir() { $tmp_locations = array('/tmp', '/var/tmp', 'c:\WUTemp', 'c:\temp', 'c:\windows\temp', 'c:\winnt\temp'); diff --git a/framework/gii/components/Pear/Text/Diff/Engine/native.php b/framework/gii/components/Pear/Text/Diff/Engine/native.php index 7af1db5297..4b56846785 100644 --- a/framework/gii/components/Pear/Text/Diff/Engine/native.php +++ b/framework/gii/components/Pear/Text/Diff/Engine/native.php @@ -191,7 +191,8 @@ function _diag ($xoff, $xlim, $yoff, $ylim, $nchunks) continue; } $matches = $ymatches[$line]; - while (($y = array_shift($matches)) !== null) { + reset($matches); + foreach ($matches as list(, $y)) { if (empty($this->in_seq[$y])) { $k = $this->_lcsPos($y); assert($k > 0); @@ -199,7 +200,7 @@ function _diag ($xoff, $xlim, $yoff, $ylim, $nchunks) break; } } - while (($y = array_shift($matches)) !== null) { + foreach ($matches as list(, $y)) { if ($y > $this->seq[$k - 1]) { assert($y <= $this->seq[$k]); /* Optimization: this is a common case: next match is diff --git a/framework/gii/components/Pear/Text/Diff/Mapped.php b/framework/gii/components/Pear/Text/Diff/Mapped.php index 4314705173..98347c0d21 100644 --- a/framework/gii/components/Pear/Text/Diff/Mapped.php +++ b/framework/gii/components/Pear/Text/Diff/Mapped.php @@ -34,7 +34,7 @@ function __construct($from_lines, $to_lines, assert(count($from_lines) == count($mapped_from_lines)); assert(count($to_lines) == count($mapped_to_lines)); - parent::Text_Diff($mapped_from_lines, $mapped_to_lines); + parent::__construct($mapped_from_lines, $mapped_to_lines); $xi = $yi = 0; for ($i = 0; $i < count($this->_edits); $i++) { From 72d8ed25d991b4b01170a3993cba57f28f1912b1 Mon Sep 17 00:00:00 2001 From: Marco van 't Wout Date: Wed, 27 Sep 2023 16:02:30 +0200 Subject: [PATCH 2/3] Port PHP compatibility fixes from https://github.com/pear/Text_Diff/pull/8 preventing "Creation of dynamic property Text_Diff_Engine_native::$xchanged is deprecated" on PHP 8.2 --- .../Pear/Text/Diff/Engine/native.php | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/framework/gii/components/Pear/Text/Diff/Engine/native.php b/framework/gii/components/Pear/Text/Diff/Engine/native.php index 4b56846785..8e08c7f510 100644 --- a/framework/gii/components/Pear/Text/Diff/Engine/native.php +++ b/framework/gii/components/Pear/Text/Diff/Engine/native.php @@ -30,6 +30,16 @@ */ class Text_Diff_Engine_native { + public $xchanged; + public $ychanged; + public $xv; + public $yv; + public $xind; + public $yind; + public $seq; + public $in_seq; + public $lcs; + function diff($from_lines, $to_lines) { array_walk($from_lines, array('Text_Diff', 'trimNewlines')); @@ -63,9 +73,11 @@ function diff($from_lines, $to_lines) } // Ignore lines which do not exist in both files. + $xhash = []; for ($xi = $skip; $xi < $n_from - $endskip; $xi++) { $xhash[$from_lines[$xi]] = 1; } + $yhash = []; for ($yi = $skip; $yi < $n_to - $endskip; $yi++) { $line = $to_lines[$yi]; if (($this->ychanged[$yi] = empty($xhash[$line]))) { @@ -160,6 +172,7 @@ function _diag ($xoff, $xlim, $yoff, $ylim, $nchunks) = array($yoff, $ylim, $xoff, $xlim); } + $ymatches = array(); if ($flip) { for ($i = $ylim - 1; $i >= $yoff; $i--) { $ymatches[$this->xv[$i]][] = $i; @@ -173,7 +186,7 @@ function _diag ($xoff, $xlim, $yoff, $ylim, $nchunks) $this->lcs = 0; $this->seq[0]= $yoff - 1; $this->in_seq = array(); - $ymids[0] = array(); + $ymids = array(array()); $numer = $xlim - $xoff + $nchunks - 1; $x = $xoff; @@ -192,15 +205,16 @@ function _diag ($xoff, $xlim, $yoff, $ylim, $nchunks) } $matches = $ymatches[$line]; reset($matches); - foreach ($matches as list(, $y)) { + while ($y = current($matches)) { if (empty($this->in_seq[$y])) { $k = $this->_lcsPos($y); assert($k > 0); $ymids[$k] = $ymids[$k - 1]; break; } + next($matches); } - foreach ($matches as list(, $y)) { + while ($y = current($matches)) { if ($y > $this->seq[$k - 1]) { assert($y <= $this->seq[$k]); /* Optimization: this is a common case: next match is @@ -213,11 +227,12 @@ function _diag ($xoff, $xlim, $yoff, $ylim, $nchunks) assert($k > 0); $ymids[$k] = $ymids[$k - 1]; } + next($matches); } } } - $seps[] = $flip ? array($yoff, $xoff) : array($xoff, $yoff); + $seps = array($flip ? array($yoff, $xoff) : array($xoff, $yoff)); $ymid = $ymids[$this->lcs]; for ($n = 0; $n < $nchunks - 1; $n++) { $x1 = $xoff + (int)(($numer + ($xlim - $xoff) * $n) / $nchunks); From 9f6583fcf80bd4b16e428d8d45f4e87b284a03b7 Mon Sep 17 00:00:00 2001 From: Marco van 't Wout Date: Wed, 27 Sep 2023 16:05:45 +0200 Subject: [PATCH 3/3] Update CHANGELOG --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index d82c62930f..c8ee5f86a8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,7 @@ Version 1.1.29 under development - Bug #4516: PHP 8 compatibility: Allow union types and intersection types in action declarations (wtommyw) - Bug #4523: Fixed translated in Greek class messages in framework requirements view, which they should not be translated (lourdas) +- Bug #4534: PHP 8.2 compatibility: Fix deprecated dynamic properties in gii/components/Pear/Text/Diff (mdeweerd, marcovtwout) - Enh #4529: Exceptions thrown while loading fixture file rows now contain more details (eduardor2k) Version 1.1.28 February 28, 2023