Fixes for PHP 8

This commit is contained in:
Dave Umrysh 2022-11-15 07:34:13 -07:00
parent 8818450302
commit c643d2702c
7 changed files with 37 additions and 37 deletions

View File

@ -2183,7 +2183,7 @@ class PHPExcel_Calculation {
*/
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
@ -2291,9 +2291,9 @@ class PHPExcel_Calculation {
// Basic validation that this is indeed a formula
// We return an empty array if not
$formula = trim($formula);
if ((!isset($formula{0})) || ($formula{0} != '=')) return array();
if ((!isset($formula[0])) || ($formula[0] != '=')) return array();
$formula = ltrim(substr($formula,1));
if (!isset($formula{0})) return array();
if (!isset($formula[0])) return array();
// Parse the formula and return the token stack
return $this->_parseFormula($formula);
@ -2369,9 +2369,9 @@ class PHPExcel_Calculation {
// Basic validation that this is indeed a formula
// We simply return the cell value if not
$formula = trim($formula);
if ($formula{0} != '=') return self::_wrapResult($formula);
if ($formula[0] != '=') return self::_wrapResult($formula);
$formula = ltrim(substr($formula,1));
if (!isset($formula{0})) return self::_wrapResult($formula);
if (!isset($formula[0])) return self::_wrapResult($formula);
$pCellParent = ($pCell !== NULL) ? $pCell->getWorksheet() : NULL;
$wsTitle = ($pCellParent !== NULL) ? $pCellParent->getTitle() : "\x00Wrk";
@ -2380,7 +2380,7 @@ class PHPExcel_Calculation {
return $cellValue;
}
if (($wsTitle{0} !== "\x00") && ($this->_cyclicReferenceStack->onStack($wsTitle.'!'.$cellID))) {
if (($wsTitle[0] !== "\x00") && ($this->_cyclicReferenceStack->onStack($wsTitle.'!'.$cellID))) {
if ($this->cyclicFormulaCount <= 0) {
return $this->_raiseFormulaError('Cyclic Reference in Formula');
} elseif (($this->_cyclicFormulaCount >= $this->cyclicFormulaCount) &&
@ -2629,7 +2629,7 @@ class PHPExcel_Calculation {
} else {
if ($value == '') {
return 'an empty string';
} elseif ($value{0} == '#') {
} elseif ($value[0] == '#') {
return 'a '.$value.' error';
} else {
$typeString = 'a string';
@ -2758,10 +2758,10 @@ class PHPExcel_Calculation {
// 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;
}
@ -2804,7 +2804,7 @@ class PHPExcel_Calculation {
else $output[] = $o2;
}
$d = $stack->last(2);
if (preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i', $d['value'], $matches)) { // Did this parenthesis just close a function?
if (!is_null($d) && preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i', $d['value'], $matches)) { // Did this parenthesis just close a function?
$functionName = $matches[1]; // Get the function name
//echo 'Closed Function is '.$functionName,PHP_EOL;
$d = $stack->pop();
@ -2934,7 +2934,7 @@ class PHPExcel_Calculation {
// If the last entry on the stack was a : operator, then we have a cell range reference
$testPrevOp = $stack->last(1);
if ($testPrevOp['value'] == ':') {
if (!is_null($testPrevOp) && $testPrevOp['value'] == ':') {
// If we have a worksheet reference, then we're playing with a 3D reference
if ($matches[2] == '') {
// Otherwise, we 'inherit' the worksheet reference from the start cell reference
@ -3036,11 +3036,11 @@ class PHPExcel_Calculation {
}
}
// 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
@ -3456,7 +3456,7 @@ class PHPExcel_Calculation {
// 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
@ -3498,11 +3498,11 @@ class PHPExcel_Calculation {
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} == '"') { $operand = self::_unwrapResult($operand); }
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;
@ -3555,8 +3555,8 @@ class PHPExcel_Calculation {
}
// Simple validate the two operands if they are string values
if (is_string($operand1) && $operand1 > '' && $operand1{0} == '"') { $operand1 = self::_unwrapResult($operand1); }
if (is_string($operand2) && $operand2 > '' && $operand2{0} == '"') { $operand2 = self::_unwrapResult($operand2); }
if (is_string($operand1) && $operand1 > '' && $operand1[0] == '"') { $operand1 = self::_unwrapResult($operand1); }
if (is_string($operand2) && $operand2 > '' && $operand2[0] == '"') { $operand2 = self::_unwrapResult($operand2); }
// Use case insensitive comparaison if not OpenOffice mode
if (PHPExcel_Calculation_Functions::getCompatibilityMode() != PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE)

View File

@ -308,9 +308,9 @@ class PHPExcel_Calculation_Functions {
public static function _ifCondition($condition) {
$condition = PHPExcel_Calculation_Functions::flattenSingleValue($condition);
if (!isset($condition{0}))
if (!isset($condition[0]))
$condition = '=""';
if (!in_array($condition{0},array('>', '<', '='))) {
if (!in_array($condition[0],array('>', '<', '='))) {
if (!is_numeric($condition)) { $condition = PHPExcel_Calculation::_wrapResult(strtoupper($condition)); }
return '='.$condition;
} else {
@ -531,7 +531,7 @@ class PHPExcel_Calculation_Functions {
break;
case 'string' :
// Errors
if ((strlen($value) > 0) && ($value{0} == '#')) {
if ((strlen($value) > 0) && ($value[0] == '#')) {
return $value;
}
break;
@ -580,7 +580,7 @@ class PHPExcel_Calculation_Functions {
return 64;
} elseif(is_string($value)) {
// Errors
if ((strlen($value) > 0) && ($value{0} == '#')) {
if ((strlen($value) > 0) && ($value[0] == '#')) {
return 16;
}
return 2;

View File

@ -769,19 +769,19 @@ class PHPExcel_Cell
// We also use the language construct isset() rather than the more costly strlen() function to match the length of $pString
// for improved performance
if (isset($pString{0})) {
if (!isset($pString{1})) {
if (isset($pString[0])) {
if (!isset($pString[1])) {
$_indexCache[$pString] = $_columnLookup[$pString];
return $_indexCache[$pString];
} elseif(!isset($pString{2})) {
$_indexCache[$pString] = $_columnLookup[$pString{0}] * 26 + $_columnLookup[$pString{1}];
} elseif(!isset($pString[2])) {
$_indexCache[$pString] = $_columnLookup[$pString[0]] * 26 + $_columnLookup[$pString[1]];
return $_indexCache[$pString];
} elseif(!isset($pString{3})) {
$_indexCache[$pString] = $_columnLookup[$pString{0}] * 676 + $_columnLookup[$pString{1}] * 26 + $_columnLookup[$pString{2}];
$_indexCache[$pString] = $_columnLookup[$pString[0]] * 676 + $_columnLookup[$pString[1]] * 26 + $_columnLookup[$pString[2]];
return $_indexCache[$pString];
}
}
throw new PHPExcel_Exception("Column string index can not be " . ((isset($pString{0})) ? "longer than 3 characters" : "empty"));
throw new PHPExcel_Exception("Column string index can not be " . ((isset($pString[0])) ? "longer than 3 characters" : "empty"));
}
/**

View File

@ -83,7 +83,7 @@ class PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder
} elseif ($pValue instanceof PHPExcel_RichText) {
return PHPExcel_Cell_DataType::TYPE_INLINE;
} elseif ($pValue{0} === '=' && strlen($pValue) > 1) {
} elseif (is_string($pValue) && $pValue[0] === '=' && strlen($pValue) > 1) {
return PHPExcel_Cell_DataType::TYPE_FORMULA;
} elseif (is_bool($pValue)) {

View File

@ -526,15 +526,15 @@ class PHPExcel_Shared_String
*/
public static function utf16_decode($str, $bom_be = TRUE) {
if( strlen($str) < 2 ) return $str;
$c0 = ord($str{0});
$c1 = ord($str{1});
$c0 = ord($str[0]);
$c1 = ord($str[1]);
if( $c0 == 0xfe && $c1 == 0xff ) { $str = substr($str,2); }
elseif( $c0 == 0xff && $c1 == 0xfe ) { $str = substr($str,2); $bom_be = false; }
$len = strlen($str);
$newstr = '';
for($i=0;$i<$len;$i+=2) {
if( $bom_be ) { $val = ord($str{$i}) << 4; $val += ord($str{$i+1}); }
else { $val = ord($str{$i+1}) << 4; $val += ord($str{$i}); }
if( $bom_be ) { $val = ord($str[$i]) << 4; $val += ord($str[$i+1]); }
else { $val = ord($str[$i+1]) << 4; $val += ord($str[$i]); }
$newstr .= ($val == 0x228) ? "\n" : chr($val);
}
return $newstr;

View File

@ -726,7 +726,7 @@ class PHPExcel_Worksheet_AutoFilter
);
} else {
// Date based
if ($dynamicRuleType{0} == 'M' || $dynamicRuleType{0} == 'Q') {
if ($dynamicRuleType[0] == 'M' || $dynamicRuleType[0] == 'Q') {
// Month or Quarter
sscanf($dynamicRuleType,'%[A-Z]%d', $periodType, $period);
if ($periodType == 'M') {

View File

@ -1115,7 +1115,7 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ
break;
case 'f': // Formula
$attributes = $pCell->getFormulaAttributes();
if($attributes['t'] == 'array') {
if(!is_null($attributes) && $attributes['t'] == 'array') {
$objWriter->startElement('f');
$objWriter->writeAttribute('t', 'array');
$objWriter->writeAttribute('ref', $pCellAddress);