Skip to content

Fix more array element accessing to use '[]' instead of '{}' #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function __construct(PHPExcel_Worksheet $parent, $arguments) {

// Set a new Memcache object and connect to the Memcache server
$this->_memcache = new Memcache();
if (!$this->_memcache->addServer($memcacheServer, $memcachePort, false, 50, 5, 5, true, array($this, 'failureCallback')) {
if (!$this->_memcache->addServer($memcacheServer, $memcachePort, false, 50, 5, 5, true, array($this, 'failureCallback'))) {
throw new Exception('Could not connect to Memcache server at '.$memcacheServer.':'.$memcachePort);
}
$this->_cacheTime = $cacheTime;
Expand All @@ -197,7 +197,7 @@ public function __construct(PHPExcel_Worksheet $parent, $arguments) {


public function failureCallback($host, $port) {
throw new Exception('memcache '.$host.':'.$port' failed');
throw new Exception('memcache '.$host.':'.$port.' failed');
}


Expand Down
30 changes: 15 additions & 15 deletions includes/PHPExcel-1.7.3c/Classes/PHPExcel/Calculation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2022,7 +2022,7 @@ public static function _wrapResult($value) {
*/
public static function _unwrapResult($value) {
if (is_string($value)) {
if ((strlen($value) > 0) && ($value{0} == '"') && (substr($value,-1) == '"')) {
if ((strlen($value) > 0) && ($value[0] == '"') && (substr($value,-1) == '"')) {
return substr($value,1,-1);
}
// Convert numeric errors to NaN error
Expand Down Expand Up @@ -2130,7 +2130,7 @@ public function parseFormula($formula) {
// Basic validation that this is indeed a formula
// We return an empty array if not
$formula = trim($formula);
if ((strlen($formula) == 0) || ($formula{0} != '=')) return array();
if ((strlen($formula) == 0) || ($formula[0] != '=')) return array();
$formula = trim(substr($formula,1));
$formulaLength = strlen($formula);
if ($formulaLength < 1) return array();
Expand Down Expand Up @@ -2186,7 +2186,7 @@ public function _calculateFormulaValue($formula, $cellID=null, PHPExcel_Cell $pC
// Basic validation that this is indeed a formula
// We simply return the "cell value" (formula) if not
$formula = trim($formula);
if ($formula{0} != '=') return self::_wrapResult($formula);
if ($formula[0] != '=') return self::_wrapResult($formula);
$formula = trim(substr($formula,1));
$formulaLength = strlen($formula);
if ($formulaLength < 1) return self::_wrapResult($formula);
Expand Down Expand Up @@ -2479,7 +2479,7 @@ private static function _showTypeDetails($value) {
case 'string' :
if ($value == '') {
return 'an empty string';
} elseif ($value{0} == '#') {
} elseif ($value[0] == '#') {
return 'a '.$value.' error';
} else {
$typeString = 'a string';
Expand Down Expand Up @@ -2602,10 +2602,10 @@ private function _parseFormula($formula) {
// Loop through the formula extracting each operator and operand in turn
while(True) {
// echo 'Assessing Expression <b>'.substr($formula, $index).'</b><br />';
$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.'<br />';
if ((in_array($opCharacter, $comparisonOperators)) && (strlen($formula) > $index) && (in_array($formula{$index+1}, $comparisonOperators))) {
$opCharacter .= $formula{++$index};
if ((in_array($opCharacter, $comparisonOperators)) && (strlen($formula) > $index) && (in_array($formula[$index+1], $comparisonOperators))) {
$opCharacter .= $formula[++$index];
// echo 'Initial character of expression block is comparison operator '.$opCharacter.'<br />';
}

Expand Down Expand Up @@ -2832,11 +2832,11 @@ private function _parseFormula($formula) {
}
}
// 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 @@ -3220,7 +3220,7 @@ private function _processTokenStack($tokens, $cellID = null, PHPExcel_Cell $pCel
// echo 'Token is a PHPExcel constant: '.$excelConstant.'<br />';
$stack->push('Constant Value',self::$_ExcelConstants[$excelConstant]);
$this->_writeDebug('Evaluating Constant '.$excelConstant.' as '.self::_showTypeDetails(self::$_ExcelConstants[$excelConstant]));
} elseif ((is_numeric($token)) || (is_bool($token)) || (is_null($token)) || ($token == '') || ($token{0} == '"') || ($token{0} == '#')) {
} elseif ((is_numeric($token)) || (is_bool($token)) || (is_null($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 @@ -3255,11 +3255,11 @@ 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} == '"') { $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->_writeDebug('Evaluation Result is '.self::_showTypeDetails($operand));
return false;
Expand Down Expand Up @@ -3312,8 +3312,8 @@ private function _executeBinaryComparisonOperation($cellID,$operand1,$operand2,$
}

// 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); }

// execute the necessary operation
switch ($operation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private function _parseToTokens() {

// Check if the formula has a valid starting =
$formulaLength = strlen($this->_formula);
if ($formulaLength < 2 || $this->_formula{0} != '=') return;
if ($formulaLength < 2 || $this->_formula[0] != '=') return;

// Helper variables
$tokens1 = $tokens2 = $stack = array();
Expand All @@ -179,8 +179,8 @@ private function _parseToTokens() {
// embeds are doubled
// end marks token
if ($inString) {
if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE) {
if ((($index + 2) <= $formulaLength) && ($this->_formula{$index + 1} == PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE)) {
if ($this->_formula[$index] == PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE) {
if ((($index + 2) <= $formulaLength) && ($this->_formula[$index + 1] == PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE)) {
$value .= PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE;
++$index;
} else {
Expand All @@ -189,7 +189,7 @@ private function _parseToTokens() {
$value = "";
}
} else {
$value .= $this->_formula{$index};
$value .= $this->_formula[$index];
}
++$index;
continue;
Expand All @@ -199,15 +199,15 @@ private function _parseToTokens() {
// embeds are double
// end does not mark a token
if ($inPath) {
if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE) {
if ((($index + 2) <= $formulaLength) && ($this->_formula{$index + 1} == PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE)) {
if ($this->_formula[$index] == PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE) {
if ((($index + 2) <= $formulaLength) && ($this->_formula[$index + 1] == PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE)) {
$value .= PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE;
++$index;
} else {
$inPath = false;
}
} else {
$value .= $this->_formula{$index};
$value .= $this->_formula[$index];
}
++$index;
continue;
Expand All @@ -217,18 +217,18 @@ private function _parseToTokens() {
// no embeds (changed to "()" by Excel)
// end does not mark a token
if ($inRange) {
if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::BRACKET_CLOSE) {
if ($this->_formula[$index] == PHPExcel_Calculation_FormulaParser::BRACKET_CLOSE) {
$inRange = false;
}
$value .= $this->_formula{$index};
$value .= $this->_formula[$index];
++$index;
continue;
}

// error values
// end marks a token, determined from absolute list of values
if ($inError) {
$value .= $this->_formula{$index};
$value .= $this->_formula[$index];
++$index;
if (in_array($value, $ERRORS)) {
$inError = false;
Expand All @@ -239,10 +239,10 @@ private function _parseToTokens() {
}

// scientific notation check
if (strpos(PHPExcel_Calculation_FormulaParser::OPERATORS_SN, $this->_formula{$index}) !== false) {
if (strpos(PHPExcel_Calculation_FormulaParser::OPERATORS_SN, $this->_formula[$index]) !== false) {
if (strlen($value) > 1) {
if (preg_match("/^[1-9]{1}(\.[0-9]+)?E{1}$/", $this->_formula{$index}) != 0) {
$value .= $this->_formula{$index};
if (preg_match("/^[1-9]{1}(\.[0-9]+)?E{1}$/", $this->_formula[$index]) != 0) {
$value .= $this->_formula[$index];
++$index;
continue;
}
Expand All @@ -252,7 +252,7 @@ private function _parseToTokens() {
// independent character evaluation (order not important)

// establish state-dependent character evaluations
if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE) {
if ($this->_formula[$index] == PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE) {
if (strlen($value > 0)) { // unexpected
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN);
$value = "";
Expand All @@ -262,7 +262,7 @@ private function _parseToTokens() {
continue;
}

if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE) {
if ($this->_formula[$index] == PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE) {
if (strlen($value) > 0) { // unexpected
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN);
$value = "";
Expand All @@ -272,14 +272,14 @@ private function _parseToTokens() {
continue;
}

if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::BRACKET_OPEN) {
if ($this->_formula[$index] == PHPExcel_Calculation_FormulaParser::BRACKET_OPEN) {
$inRange = true;
$value .= PHPExcel_Calculation_FormulaParser::BRACKET_OPEN;
++$index;
continue;
}

if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::ERROR_START) {
if ($this->_formula[$index] == PHPExcel_Calculation_FormulaParser::ERROR_START) {
if (strlen($value) > 0) { // unexpected
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN);
$value = "";
Expand All @@ -291,7 +291,7 @@ private function _parseToTokens() {
}

// mark start and end of arrays and array rows
if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::BRACE_OPEN) {
if ($this->_formula[$index] == PHPExcel_Calculation_FormulaParser::BRACE_OPEN) {
if (strlen($value) > 0) { // unexpected
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN);
$value = "";
Expand All @@ -309,7 +309,7 @@ private function _parseToTokens() {
continue;
}

if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::SEMICOLON) {
if ($this->_formula[$index] == PHPExcel_Calculation_FormulaParser::SEMICOLON) {
if (strlen($value) > 0) {
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND);
$value = "";
Expand All @@ -331,7 +331,7 @@ private function _parseToTokens() {
continue;
}

if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::BRACE_CLOSE) {
if ($this->_formula[$index] == PHPExcel_Calculation_FormulaParser::BRACE_CLOSE) {
if (strlen($value) > 0) {
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND);
$value = "";
Expand All @@ -352,14 +352,14 @@ private function _parseToTokens() {
}

// trim white-space
if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::WHITESPACE) {
if ($this->_formula[$index] == PHPExcel_Calculation_FormulaParser::WHITESPACE) {
if (strlen($value) > 0) {
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND);
$value = "";
}
$tokens1[] = new PHPExcel_Calculation_FormulaToken("", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_WHITESPACE);
++$index;
while (($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::WHITESPACE) && ($index < $formulaLength)) {
while (($this->_formula[$index] == PHPExcel_Calculation_FormulaParser::WHITESPACE) && ($index < $formulaLength)) {
++$index;
}
continue;
Expand All @@ -379,29 +379,29 @@ private function _parseToTokens() {
}

// standard infix operators
if (strpos(PHPExcel_Calculation_FormulaParser::OPERATORS_INFIX, $this->_formula{$index}) !== false) {
if (strpos(PHPExcel_Calculation_FormulaParser::OPERATORS_INFIX, $this->_formula[$index]) !== false) {
if (strlen($value) > 0) {
$tokens1[] =new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND);
$value = "";
}
$tokens1[] = new PHPExcel_Calculation_FormulaToken($this->_formula{$index}, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX);
$tokens1[] = new PHPExcel_Calculation_FormulaToken($this->_formula[$index], PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX);
++$index;
continue;
}

// standard postfix operators (only one)
if (strpos(PHPExcel_Calculation_FormulaParser::OPERATORS_POSTFIX, $this->_formula{$index}) !== false) {
if (strpos(PHPExcel_Calculation_FormulaParser::OPERATORS_POSTFIX, $this->_formula[$index]) !== false) {
if (strlen($value) > 0) {
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND);
$value = "";
}
$tokens1[] = new PHPExcel_Calculation_FormulaToken($this->_formula{$index}, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPOSTFIX);
$tokens1[] = new PHPExcel_Calculation_FormulaToken($this->_formula[$index], PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPOSTFIX);
++$index;
continue;
}

// start subexpression or function
if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::PAREN_OPEN) {
if ($this->_formula[$index] == PHPExcel_Calculation_FormulaParser::PAREN_OPEN) {
if (strlen($value) > 0) {
$tmp = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START);
$tokens1[] = $tmp;
Expand All @@ -417,7 +417,7 @@ private function _parseToTokens() {
}

// function, subexpression, or array parameters, or operand unions
if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::COMMA) {
if ($this->_formula[$index] == PHPExcel_Calculation_FormulaParser::COMMA) {
if (strlen($value) > 0) {
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND);
$value = "";
Expand All @@ -438,7 +438,7 @@ private function _parseToTokens() {
}

// stop subexpression
if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::PAREN_CLOSE) {
if ($this->_formula[$index] == PHPExcel_Calculation_FormulaParser::PAREN_CLOSE) {
if (strlen($value) > 0) {
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND);
$value = "";
Expand All @@ -454,7 +454,7 @@ private function _parseToTokens() {
}

// token accumulation
$value .= $this->_formula{$index};
$value .= $this->_formula[$index];
++$index;
}

Expand Down
Loading