Skip to content

Commit

Permalink
Merge pull request #1 from valiton/update-php-8
Browse files Browse the repository at this point in the history
Update PHP 8 support
  • Loading branch information
nymo committed Jun 13, 2024
2 parents 995cf54 + af6a33b commit bdd6ede
Show file tree
Hide file tree
Showing 28 changed files with 336 additions and 209 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ analysis
*.project
/.settings
/.idea
/vendor
36 changes: 18 additions & 18 deletions Classes/PHPExcel/Calculation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2548,7 +2548,7 @@ public static function wrapResult($value)
public static function unwrapResult($value)
{
if (is_string($value)) {
if ((isset($value{0})) && ($value{0} == '"') && (substr($value, -1) == '"')) {
if ((isset($value[0])) && ($value[0] == '"') && (substr($value, -1) == '"')) {
return substr($value, 1, -1);
}
// Convert numeric errors to NaN error
Expand Down Expand Up @@ -2669,11 +2669,11 @@ public function parseFormula($formula)
// Basic validation that this is indeed a formula
// We return an empty array if not
$formula = trim($formula);
if ((!isset($formula{0})) || ($formula{0} != '=')) {
if ((!isset($formula[0])) || ($formula[0] != '=')) {
return array();
}
$formula = ltrim(substr($formula, 1));
if (!isset($formula{0})) {
if (!isset($formula[0])) {
return array();
}

Expand Down Expand Up @@ -2761,11 +2761,11 @@ public function _calculateFormulaValue($formula, $cellID = null, PHPExcel_Cell $
// Basic validation that this is indeed a formula
// We simply return the cell value if not
$formula = trim($formula);
if ($formula{0} != '=') {
if ($formula[0] != '=') {
return self::wrapResult($formula);
}
$formula = ltrim(substr($formula, 1));
if (!isset($formula{0})) {
if (!isset($formula[0])) {
return self::wrapResult($formula);
}

Expand All @@ -2777,7 +2777,7 @@ public function _calculateFormulaValue($formula, $cellID = null, PHPExcel_Cell $
return $cellValue;
}

if (($wsTitle{0} !== "\x00") && ($this->cyclicReferenceStack->onStack($wsCellReference))) {
if (($wsTitle[0] !== "\x00") && ($this->cyclicReferenceStack->onStack($wsCellReference))) {
if ($this->cyclicFormulaCount <= 0) {
$this->cyclicFormulaCell = '';
return $this->raiseFormulaError('Cyclic Reference in Formula');
Expand Down Expand Up @@ -3031,7 +3031,7 @@ private function showTypeDetails($value)
} else {
if ($value == '') {
return 'an empty string';
} elseif ($value{0} == '#') {
} elseif ($value[0] == '#') {
return 'a '.$value.' error';
} else {
$typeString = 'a string';
Expand Down Expand Up @@ -3163,10 +3163,10 @@ private function _parseFormula($formula, PHPExcel_Cell $pCell = null)
// Loop through the formula extracting each operator and operand in turn
while (true) {
//echo 'Assessing Expression '.substr($formula, $index), PHP_EOL;
$opCharacter = $formula{$index}; // Get the first character of the value at the current index position
$opCharacter = $formula[$index]; // Get the first character of the value at the current index position
//echo 'Initial character of expression block is '.$opCharacter, PHP_EOL;
if ((isset(self::$comparisonOperators[$opCharacter])) && (strlen($formula) > $index) && (isset(self::$comparisonOperators[$formula{$index+1}]))) {
$opCharacter .= $formula{++$index};
if ((isset(self::$comparisonOperators[$opCharacter])) && (strlen($formula) > $index) && (isset(self::$comparisonOperators[$formula[$index+1]]))) {
$opCharacter .= $formula[++$index];
//echo 'Initial character of expression block is comparison operator '.$opCharacter.PHP_EOL;
}

Expand Down Expand Up @@ -3454,11 +3454,11 @@ private function _parseFormula($formula, PHPExcel_Cell $pCell = null)
}
}
// Ignore white space
while (($formula{$index} == "\n") || ($formula{$index} == "\r")) {
while (($formula[$index] == "\n") || ($formula[$index] == "\r")) {
++$index;
}
if ($formula{$index} == ' ') {
while ($formula{$index} == ' ') {
if ($formula[$index] == ' ') {
while ($formula[$index] == ' ') {
++$index;
}
// If we're expecting an operator, but only have a space between the previous and next operands (and both are
Expand Down Expand Up @@ -3888,7 +3888,7 @@ private function processTokenStack($tokens, $cellID = null, PHPExcel_Cell $pCell
// echo 'Token is a PHPExcel constant: '.$excelConstant.'<br />';
$stack->push('Constant Value', self::$excelConstants[$excelConstant]);
$this->_debugLog->writeDebugLog('Evaluating Constant ', $excelConstant, ' as ', $this->showTypeDetails(self::$excelConstants[$excelConstant]));
} elseif ((is_numeric($token)) || ($token === null) || (is_bool($token)) || ($token == '') || ($token{0} == '"') || ($token{0} == '#')) {
} elseif ((is_numeric($token)) || ($token === null) || (is_bool($token)) || ($token == '') || ($token[0] == '"') || ($token[0] == '#')) {
// echo 'Token is a number, boolean, string, null or an Excel error<br />';
$stack->push('Value', $token);
// if the token is a named range, push the named range name onto the stack
Expand Down Expand Up @@ -3933,13 +3933,13 @@ private function validateBinaryOperand($cellID, &$operand, &$stack)
if (is_string($operand)) {
// We only need special validations for the operand if it is a string
// Start by stripping off the quotation marks we use to identify true excel string values internally
if ($operand > '' && $operand{0} == '"') {
if ($operand > '' && $operand[0] == '"') {
$operand = self::unwrapResult($operand);
}
// If the string is a numeric value, we treat it as a numeric, so no further testing
if (!is_numeric($operand)) {
// If not a numeric, test to see if the value is an Excel error, and so can't be used in normal binary operations
if ($operand > '' && $operand{0} == '#') {
if ($operand > '' && $operand[0] == '#') {
$stack->push('Value', $operand);
$this->_debugLog->writeDebugLog('Evaluation Result is ', $this->showTypeDetails($operand));
return false;
Expand Down Expand Up @@ -3995,10 +3995,10 @@ private function executeBinaryComparisonOperation($cellID, $operand1, $operand2,
}

// Simple validate the two operands if they are string values
if (is_string($operand1) && $operand1 > '' && $operand1{0} == '"') {
if (is_string($operand1) && $operand1 > '' && $operand1[0] == '"') {
$operand1 = self::unwrapResult($operand1);
}
if (is_string($operand2) && $operand2 > '' && $operand2{0} == '"') {
if (is_string($operand2) && $operand2 > '' && $operand2[0] == '"') {
$operand2 = self::unwrapResult($operand2);
}

Expand Down
10 changes: 5 additions & 5 deletions Classes/PHPExcel/Calculation/Engineering.php
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ public static function parseComplex($complexNumber)
// Split the input into its Real and Imaginary components
$leadingSign = 0;
if (strlen($workString) > 0) {
$leadingSign = (($workString{0} == '+') || ($workString{0} == '-')) ? 1 : 0;
$leadingSign = (($workString[0] == '+') || ($workString[0] == '-')) ? 1 : 0;
}
$power = '';
$realNumber = strtok($workString, '+-');
Expand Down Expand Up @@ -809,16 +809,16 @@ public static function parseComplex($complexNumber)
*/
private static function cleanComplex($complexNumber)
{
if ($complexNumber{0} == '+') {
if ($complexNumber[0] == '+') {
$complexNumber = substr($complexNumber, 1);
}
if ($complexNumber{0} == '0') {
if ($complexNumber[0] == '0') {
$complexNumber = substr($complexNumber, 1);
}
if ($complexNumber{0} == '.') {
if ($complexNumber[0] == '.') {
$complexNumber = '0'.$complexNumber;
}
if ($complexNumber{0} == '+') {
if ($complexNumber[0] == '+') {
$complexNumber = substr($complexNumber, 1);
}
return $complexNumber;
Expand Down
Loading

0 comments on commit bdd6ede

Please sign in to comment.