Fixes for PHP 8
This commit is contained in:
parent
8818450302
commit
c643d2702c
@ -2183,7 +2183,7 @@ class PHPExcel_Calculation {
|
|||||||
*/
|
*/
|
||||||
public static function _unwrapResult($value) {
|
public static function _unwrapResult($value) {
|
||||||
if (is_string($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);
|
return substr($value,1,-1);
|
||||||
}
|
}
|
||||||
// Convert numeric errors to NaN error
|
// Convert numeric errors to NaN error
|
||||||
@ -2291,9 +2291,9 @@ class PHPExcel_Calculation {
|
|||||||
// Basic validation that this is indeed a formula
|
// Basic validation that this is indeed a formula
|
||||||
// We return an empty array if not
|
// We return an empty array if not
|
||||||
$formula = trim($formula);
|
$formula = trim($formula);
|
||||||
if ((!isset($formula{0})) || ($formula{0} != '=')) return array();
|
if ((!isset($formula[0])) || ($formula[0] != '=')) return array();
|
||||||
$formula = ltrim(substr($formula,1));
|
$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
|
// Parse the formula and return the token stack
|
||||||
return $this->_parseFormula($formula);
|
return $this->_parseFormula($formula);
|
||||||
@ -2369,9 +2369,9 @@ class PHPExcel_Calculation {
|
|||||||
// Basic validation that this is indeed a formula
|
// Basic validation that this is indeed a formula
|
||||||
// We simply return the cell value if not
|
// We simply return the cell value if not
|
||||||
$formula = trim($formula);
|
$formula = trim($formula);
|
||||||
if ($formula{0} != '=') return self::_wrapResult($formula);
|
if ($formula[0] != '=') return self::_wrapResult($formula);
|
||||||
$formula = ltrim(substr($formula,1));
|
$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;
|
$pCellParent = ($pCell !== NULL) ? $pCell->getWorksheet() : NULL;
|
||||||
$wsTitle = ($pCellParent !== NULL) ? $pCellParent->getTitle() : "\x00Wrk";
|
$wsTitle = ($pCellParent !== NULL) ? $pCellParent->getTitle() : "\x00Wrk";
|
||||||
@ -2380,7 +2380,7 @@ class PHPExcel_Calculation {
|
|||||||
return $cellValue;
|
return $cellValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($wsTitle{0} !== "\x00") && ($this->_cyclicReferenceStack->onStack($wsTitle.'!'.$cellID))) {
|
if (($wsTitle[0] !== "\x00") && ($this->_cyclicReferenceStack->onStack($wsTitle.'!'.$cellID))) {
|
||||||
if ($this->cyclicFormulaCount <= 0) {
|
if ($this->cyclicFormulaCount <= 0) {
|
||||||
return $this->_raiseFormulaError('Cyclic Reference in Formula');
|
return $this->_raiseFormulaError('Cyclic Reference in Formula');
|
||||||
} elseif (($this->_cyclicFormulaCount >= $this->cyclicFormulaCount) &&
|
} elseif (($this->_cyclicFormulaCount >= $this->cyclicFormulaCount) &&
|
||||||
@ -2629,7 +2629,7 @@ class PHPExcel_Calculation {
|
|||||||
} else {
|
} else {
|
||||||
if ($value == '') {
|
if ($value == '') {
|
||||||
return 'an empty string';
|
return 'an empty string';
|
||||||
} elseif ($value{0} == '#') {
|
} elseif ($value[0] == '#') {
|
||||||
return 'a '.$value.' error';
|
return 'a '.$value.' error';
|
||||||
} else {
|
} else {
|
||||||
$typeString = 'a string';
|
$typeString = 'a string';
|
||||||
@ -2758,10 +2758,10 @@ class PHPExcel_Calculation {
|
|||||||
// Loop through the formula extracting each operator and operand in turn
|
// Loop through the formula extracting each operator and operand in turn
|
||||||
while(TRUE) {
|
while(TRUE) {
|
||||||
//echo 'Assessing Expression '.substr($formula, $index),PHP_EOL;
|
//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;
|
//echo 'Initial character of expression block is '.$opCharacter,PHP_EOL;
|
||||||
if ((isset(self::$_comparisonOperators[$opCharacter])) && (strlen($formula) > $index) && (isset(self::$_comparisonOperators[$formula{$index+1}]))) {
|
if ((isset(self::$_comparisonOperators[$opCharacter])) && (strlen($formula) > $index) && (isset(self::$_comparisonOperators[$formula[$index+1]]))) {
|
||||||
$opCharacter .= $formula{++$index};
|
$opCharacter .= $formula[++$index];
|
||||||
//echo 'Initial character of expression block is comparison operator '.$opCharacter.PHP_EOL;
|
//echo 'Initial character of expression block is comparison operator '.$opCharacter.PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2804,7 +2804,7 @@ class PHPExcel_Calculation {
|
|||||||
else $output[] = $o2;
|
else $output[] = $o2;
|
||||||
}
|
}
|
||||||
$d = $stack->last(2);
|
$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
|
$functionName = $matches[1]; // Get the function name
|
||||||
//echo 'Closed Function is '.$functionName,PHP_EOL;
|
//echo 'Closed Function is '.$functionName,PHP_EOL;
|
||||||
$d = $stack->pop();
|
$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
|
// If the last entry on the stack was a : operator, then we have a cell range reference
|
||||||
$testPrevOp = $stack->last(1);
|
$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 we have a worksheet reference, then we're playing with a 3D reference
|
||||||
if ($matches[2] == '') {
|
if ($matches[2] == '') {
|
||||||
// Otherwise, we 'inherit' the worksheet reference from the start cell reference
|
// Otherwise, we 'inherit' the worksheet reference from the start cell reference
|
||||||
@ -3036,11 +3036,11 @@ class PHPExcel_Calculation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Ignore white space
|
// Ignore white space
|
||||||
while (($formula{$index} == "\n") || ($formula{$index} == "\r")) {
|
while (($formula[$index] == "\n") || ($formula[$index] == "\r")) {
|
||||||
++$index;
|
++$index;
|
||||||
}
|
}
|
||||||
if ($formula{$index} == ' ') {
|
if ($formula[$index] == ' ') {
|
||||||
while ($formula{$index} == ' ') {
|
while ($formula[$index] == ' ') {
|
||||||
++$index;
|
++$index;
|
||||||
}
|
}
|
||||||
// If we're expecting an operator, but only have a space between the previous and next operands (and both are
|
// 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 />';
|
// echo 'Token is a PHPExcel constant: '.$excelConstant.'<br />';
|
||||||
$stack->push('Constant Value',self::$_ExcelConstants[$excelConstant]);
|
$stack->push('Constant Value',self::$_ExcelConstants[$excelConstant]);
|
||||||
$this->_debugLog->writeDebugLog('Evaluating Constant ', $excelConstant, ' as ', $this->_showTypeDetails(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 />';
|
// echo 'Token is a number, boolean, string, null or an Excel error<br />';
|
||||||
$stack->push('Value',$token);
|
$stack->push('Value',$token);
|
||||||
// if the token is a named range, push the named range name onto the stack
|
// 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)) {
|
if (is_string($operand)) {
|
||||||
// We only need special validations for the operand if it is a string
|
// 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
|
// 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 the string is a numeric value, we treat it as a numeric, so no further testing
|
||||||
if (!is_numeric($operand)) {
|
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 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);
|
$stack->push('Value', $operand);
|
||||||
$this->_debugLog->writeDebugLog('Evaluation Result is ', $this->_showTypeDetails($operand));
|
$this->_debugLog->writeDebugLog('Evaluation Result is ', $this->_showTypeDetails($operand));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -3555,8 +3555,8 @@ class PHPExcel_Calculation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Simple validate the two operands if they are string values
|
// Simple validate the two operands if they are string values
|
||||||
if (is_string($operand1) && $operand1 > '' && $operand1{0} == '"') { $operand1 = self::_unwrapResult($operand1); }
|
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($operand2) && $operand2 > '' && $operand2[0] == '"') { $operand2 = self::_unwrapResult($operand2); }
|
||||||
|
|
||||||
// Use case insensitive comparaison if not OpenOffice mode
|
// Use case insensitive comparaison if not OpenOffice mode
|
||||||
if (PHPExcel_Calculation_Functions::getCompatibilityMode() != PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE)
|
if (PHPExcel_Calculation_Functions::getCompatibilityMode() != PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE)
|
||||||
|
@ -308,9 +308,9 @@ class PHPExcel_Calculation_Functions {
|
|||||||
|
|
||||||
public static function _ifCondition($condition) {
|
public static function _ifCondition($condition) {
|
||||||
$condition = PHPExcel_Calculation_Functions::flattenSingleValue($condition);
|
$condition = PHPExcel_Calculation_Functions::flattenSingleValue($condition);
|
||||||
if (!isset($condition{0}))
|
if (!isset($condition[0]))
|
||||||
$condition = '=""';
|
$condition = '=""';
|
||||||
if (!in_array($condition{0},array('>', '<', '='))) {
|
if (!in_array($condition[0],array('>', '<', '='))) {
|
||||||
if (!is_numeric($condition)) { $condition = PHPExcel_Calculation::_wrapResult(strtoupper($condition)); }
|
if (!is_numeric($condition)) { $condition = PHPExcel_Calculation::_wrapResult(strtoupper($condition)); }
|
||||||
return '='.$condition;
|
return '='.$condition;
|
||||||
} else {
|
} else {
|
||||||
@ -531,7 +531,7 @@ class PHPExcel_Calculation_Functions {
|
|||||||
break;
|
break;
|
||||||
case 'string' :
|
case 'string' :
|
||||||
// Errors
|
// Errors
|
||||||
if ((strlen($value) > 0) && ($value{0} == '#')) {
|
if ((strlen($value) > 0) && ($value[0] == '#')) {
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -580,7 +580,7 @@ class PHPExcel_Calculation_Functions {
|
|||||||
return 64;
|
return 64;
|
||||||
} elseif(is_string($value)) {
|
} elseif(is_string($value)) {
|
||||||
// Errors
|
// Errors
|
||||||
if ((strlen($value) > 0) && ($value{0} == '#')) {
|
if ((strlen($value) > 0) && ($value[0] == '#')) {
|
||||||
return 16;
|
return 16;
|
||||||
}
|
}
|
||||||
return 2;
|
return 2;
|
||||||
|
@ -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
|
// We also use the language construct isset() rather than the more costly strlen() function to match the length of $pString
|
||||||
// for improved performance
|
// for improved performance
|
||||||
if (isset($pString{0})) {
|
if (isset($pString[0])) {
|
||||||
if (!isset($pString{1})) {
|
if (!isset($pString[1])) {
|
||||||
$_indexCache[$pString] = $_columnLookup[$pString];
|
$_indexCache[$pString] = $_columnLookup[$pString];
|
||||||
return $_indexCache[$pString];
|
return $_indexCache[$pString];
|
||||||
} elseif(!isset($pString{2})) {
|
} elseif(!isset($pString[2])) {
|
||||||
$_indexCache[$pString] = $_columnLookup[$pString{0}] * 26 + $_columnLookup[$pString{1}];
|
$_indexCache[$pString] = $_columnLookup[$pString[0]] * 26 + $_columnLookup[$pString[1]];
|
||||||
return $_indexCache[$pString];
|
return $_indexCache[$pString];
|
||||||
} elseif(!isset($pString{3})) {
|
} 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];
|
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"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,7 +83,7 @@ class PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder
|
|||||||
} elseif ($pValue instanceof PHPExcel_RichText) {
|
} elseif ($pValue instanceof PHPExcel_RichText) {
|
||||||
return PHPExcel_Cell_DataType::TYPE_INLINE;
|
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;
|
return PHPExcel_Cell_DataType::TYPE_FORMULA;
|
||||||
|
|
||||||
} elseif (is_bool($pValue)) {
|
} elseif (is_bool($pValue)) {
|
||||||
|
@ -526,15 +526,15 @@ class PHPExcel_Shared_String
|
|||||||
*/
|
*/
|
||||||
public static function utf16_decode($str, $bom_be = TRUE) {
|
public static function utf16_decode($str, $bom_be = TRUE) {
|
||||||
if( strlen($str) < 2 ) return $str;
|
if( strlen($str) < 2 ) return $str;
|
||||||
$c0 = ord($str{0});
|
$c0 = ord($str[0]);
|
||||||
$c1 = ord($str{1});
|
$c1 = ord($str[1]);
|
||||||
if( $c0 == 0xfe && $c1 == 0xff ) { $str = substr($str,2); }
|
if( $c0 == 0xfe && $c1 == 0xff ) { $str = substr($str,2); }
|
||||||
elseif( $c0 == 0xff && $c1 == 0xfe ) { $str = substr($str,2); $bom_be = false; }
|
elseif( $c0 == 0xff && $c1 == 0xfe ) { $str = substr($str,2); $bom_be = false; }
|
||||||
$len = strlen($str);
|
$len = strlen($str);
|
||||||
$newstr = '';
|
$newstr = '';
|
||||||
for($i=0;$i<$len;$i+=2) {
|
for($i=0;$i<$len;$i+=2) {
|
||||||
if( $bom_be ) { $val = ord($str{$i}) << 4; $val += ord($str{$i+1}); }
|
if( $bom_be ) { $val = ord($str[$i]) << 4; $val += ord($str[$i+1]); }
|
||||||
else { $val = ord($str{$i+1}) << 4; $val += ord($str{$i}); }
|
else { $val = ord($str[$i+1]) << 4; $val += ord($str[$i]); }
|
||||||
$newstr .= ($val == 0x228) ? "\n" : chr($val);
|
$newstr .= ($val == 0x228) ? "\n" : chr($val);
|
||||||
}
|
}
|
||||||
return $newstr;
|
return $newstr;
|
||||||
|
@ -726,7 +726,7 @@ class PHPExcel_Worksheet_AutoFilter
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// Date based
|
// Date based
|
||||||
if ($dynamicRuleType{0} == 'M' || $dynamicRuleType{0} == 'Q') {
|
if ($dynamicRuleType[0] == 'M' || $dynamicRuleType[0] == 'Q') {
|
||||||
// Month or Quarter
|
// Month or Quarter
|
||||||
sscanf($dynamicRuleType,'%[A-Z]%d', $periodType, $period);
|
sscanf($dynamicRuleType,'%[A-Z]%d', $periodType, $period);
|
||||||
if ($periodType == 'M') {
|
if ($periodType == 'M') {
|
||||||
|
@ -1115,7 +1115,7 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ
|
|||||||
break;
|
break;
|
||||||
case 'f': // Formula
|
case 'f': // Formula
|
||||||
$attributes = $pCell->getFormulaAttributes();
|
$attributes = $pCell->getFormulaAttributes();
|
||||||
if($attributes['t'] == 'array') {
|
if(!is_null($attributes) && $attributes['t'] == 'array') {
|
||||||
$objWriter->startElement('f');
|
$objWriter->startElement('f');
|
||||||
$objWriter->writeAttribute('t', 'array');
|
$objWriter->writeAttribute('t', 'array');
|
||||||
$objWriter->writeAttribute('ref', $pCellAddress);
|
$objWriter->writeAttribute('ref', $pCellAddress);
|
||||||
|
Loading…
Reference in New Issue
Block a user