Skip to content
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

Compatibility with PHP 7+ #183

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 8 additions & 9 deletions SpreadsheetReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ private static function Load($Type)
* Rewind the Iterator to the first element.
* Similar to the reset() function for arrays in PHP
*/
public function rewind()
public function rewind(): void
{
$this -> Index = 0;
if ($this -> Handle)
Expand All @@ -245,6 +245,7 @@ public function rewind()
*
* @return mixed current element from the collection
*/
#[\ReturnTypeWillChange]
public function current()
{
if ($this -> Handle)
Expand All @@ -258,15 +259,14 @@ public function current()
* Move forward to next element.
* Similar to the next() function for arrays in PHP
*/
public function next()
public function next(): void
{
if ($this -> Handle)
{
$this -> Index++;

return $this -> Handle -> next();
$this -> Handle -> next();
}
return null;
}

/**
Expand All @@ -275,6 +275,7 @@ public function next()
*
* @return mixed either an integer or a string
*/
#[\ReturnTypeWillChange]
public function key()
{
if ($this -> Handle)
Expand All @@ -290,7 +291,7 @@ public function key()
*
* @return boolean FALSE if there's nothing more to iterate over
*/
public function valid()
public function valid(): bool
{
if ($this -> Handle)
{
Expand All @@ -300,7 +301,7 @@ public function valid()
}

// !Countable interface method
public function count()
public function count(): int
{
if ($this -> Handle)
{
Expand All @@ -315,7 +316,7 @@ public function count()
*
* @param int Position in file
*/
public function seek($Position)
public function seek($Position): void
{
if (!$this -> Handle)
{
Expand All @@ -341,8 +342,6 @@ public function seek($Position)
throw new OutOfBoundsException('SpreadsheetError: Position '.$Position.' not found');
}
}

return null;
}
}
?>
16 changes: 8 additions & 8 deletions SpreadsheetReader_CSV.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function ChangeSheet($Index)
* Rewind the Iterator to the first element.
* Similar to the reset() function for arrays in PHP
*/
public function rewind()
public function rewind(): void
{
fseek($this -> Handle, $this -> BOMLength);
$this -> CurrentRow = null;
Expand All @@ -169,6 +169,7 @@ public function rewind()
*
* @return mixed current element from the collection
*/
#[\ReturnTypeWillChange]
public function current()
{
if ($this -> Index == 0 && is_null($this -> CurrentRow))
Expand All @@ -183,7 +184,7 @@ public function current()
* Move forward to next element.
* Similar to the next() function for arrays in PHP
*/
public function next()
public function next(): void
{
$this -> CurrentRow = array();

Expand Down Expand Up @@ -238,8 +239,6 @@ public function next()

}
}

return $this -> CurrentRow;
}

/**
Expand All @@ -248,7 +247,8 @@ public function next()
*
* @return mixed either an integer or a string
*/
public function key()
#[\ReturnTypeWillChange]
public function key(): mixed
{
return $this -> Index;
}
Expand All @@ -259,7 +259,7 @@ public function key()
*
* @return boolean FALSE if there's nothing more to iterate over
*/
public function valid()
public function valid(): bool
{
return ($this -> CurrentRow || !feof($this -> Handle));
}
Expand All @@ -269,9 +269,9 @@ public function valid()
* Ostensibly should return the count of the contained items but this just returns the number
* of rows read so far. It's not really correct but at least coherent.
*/
public function count()
public function count(): int
{
return $this -> Index + 1;
}
}
?>
?>
14 changes: 7 additions & 7 deletions SpreadsheetReader_ODS.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function ChangeSheet($Index)
* Rewind the Iterator to the first element.
* Similar to the reset() function for arrays in PHP
*/
public function rewind()
public function rewind(): void
{
if ($this -> Index > 0)
{
Expand All @@ -182,6 +182,7 @@ public function rewind()
*
* @return mixed current element from the collection
*/
#[\ReturnTypeWillChange]
public function current()
{
if ($this -> Index == 0 && is_null($this -> CurrentRow))
Expand All @@ -196,7 +197,7 @@ public function current()
* Move forward to next element.
* Similar to the next() function for arrays in PHP
*/
public function next()
public function next(): void
{
$this -> Index++;

Expand Down Expand Up @@ -300,8 +301,6 @@ public function next()
}
}
}

return $this -> CurrentRow;
}

/**
Expand All @@ -310,6 +309,7 @@ public function next()
*
* @return mixed either an integer or a string
*/
#[\ReturnTypeWillChange]
public function key()
{
return $this -> Index;
Expand All @@ -321,7 +321,7 @@ public function key()
*
* @return boolean FALSE if there's nothing more to iterate over
*/
public function valid()
public function valid(): bool
{
return $this -> Valid;
}
Expand All @@ -331,9 +331,9 @@ public function valid()
* Ostensibly should return the count of the contained items but this just returns the number
* of rows read so far. It's not really correct but at least coherent.
*/
public function count()
public function count(): int
{
return $this -> Index + 1;
}
}
?>
?>
20 changes: 11 additions & 9 deletions SpreadsheetReader_XLS.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function __get($Name)
* Rewind the Iterator to the first element.
* Similar to the reset() function for arrays in PHP
*/
public function rewind()
public function rewind(): void
{
$this -> Index = 0;
}
Expand All @@ -176,6 +176,7 @@ public function rewind()
*
* @return mixed current element from the collection
*/
#[\ReturnTypeWillChange]
public function current()
{
if ($this -> Index == 0)
Expand All @@ -190,7 +191,7 @@ public function current()
* Move forward to next element.
* Similar to the next() function for arrays in PHP
*/
public function next()
public function next(): void
{
// Internal counter is advanced here instead of the if statement
// because apparently it's fully possible that an empty row will not be
Expand All @@ -199,26 +200,26 @@ public function next()

if ($this -> Error)
{
return array();
return;
}
elseif (isset($this -> Handle -> sheets[$this -> CurrentSheet]['cells'][$this -> Index]))
{
$this -> CurrentRow = $this -> Handle -> sheets[$this -> CurrentSheet]['cells'][$this -> Index];
if (!$this -> CurrentRow)
{
return array();
return;
}

$this -> CurrentRow = $this -> CurrentRow + $this -> EmptyRow;
ksort($this -> CurrentRow);

$this -> CurrentRow = array_values($this -> CurrentRow);
return $this -> CurrentRow;
return;
}
else
{
$this -> CurrentRow = $this -> EmptyRow;
return $this -> CurrentRow;
return;
}
}

Expand All @@ -228,6 +229,7 @@ public function next()
*
* @return mixed either an integer or a string
*/
#[\ReturnTypeWillChange]
public function key()
{
return $this -> Index;
Expand All @@ -239,7 +241,7 @@ public function key()
*
* @return boolean FALSE if there's nothing more to iterate over
*/
public function valid()
public function valid(): bool
{
if ($this -> Error)
{
Expand All @@ -253,7 +255,7 @@ public function valid()
* Ostensibly should return the count of the contained items but this just returns the number
* of rows read so far. It's not really correct but at least coherent.
*/
public function count()
public function count(): int
{
if ($this -> Error)
{
Expand All @@ -263,4 +265,4 @@ public function count()
return $this -> RowCount;
}
}
?>
?>
20 changes: 10 additions & 10 deletions SpreadsheetReader_XLSX.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ private function PrepareSharedStringCache()
case 't':
if ($this -> SharedStrings -> nodeType == XMLReader::END_ELEMENT)
{
continue;
continue 2;
}
$CacheValue .= $this -> SharedStrings -> readString();
break;
Expand Down Expand Up @@ -578,7 +578,7 @@ private function GetSharedString($Index)
case 't':
if ($this -> SharedStrings -> nodeType == XMLReader::END_ELEMENT)
{
continue;
continue 2;
}
$Value .= $this -> SharedStrings -> readString();
break;
Expand Down Expand Up @@ -941,7 +941,7 @@ public function GeneralFormat($Value)
* Rewind the Iterator to the first element.
* Similar to the reset() function for arrays in PHP
*/
public function rewind()
public function rewind(): void
{
// Removed the check whether $this -> Index == 0 otherwise ChangeSheet doesn't work properly

Expand Down Expand Up @@ -970,6 +970,7 @@ public function rewind()
*
* @return mixed current element from the collection
*/
#[\ReturnTypeWillChange]
public function current()
{
if ($this -> Index == 0 && $this -> CurrentRow === false)
Expand All @@ -984,7 +985,7 @@ public function current()
* Move forward to next element.
* Similar to the next() function for arrays in PHP
*/
public function next()
public function next(): void
{
$this -> Index++;

Expand Down Expand Up @@ -1046,7 +1047,7 @@ public function next()
// If it is a closing tag, skip it
if ($this -> Worksheet -> nodeType == XMLReader::END_ELEMENT)
{
continue;
continue 2;
}

$StyleId = (int)$this -> Worksheet -> getAttribute('s');
Expand Down Expand Up @@ -1080,7 +1081,7 @@ public function next()
case 'is':
if ($this -> Worksheet -> nodeType == XMLReader::END_ELEMENT)
{
continue;
continue 2;
}

$Value = $this -> Worksheet -> readString();
Expand Down Expand Up @@ -1113,8 +1114,6 @@ public function next()
ksort($this -> CurrentRow);
}
}

return $this -> CurrentRow;
}

/**
Expand All @@ -1123,6 +1122,7 @@ public function next()
*
* @return mixed either an integer or a string
*/
#[\ReturnTypeWillChange]
public function key()
{
return $this -> Index;
Expand All @@ -1134,7 +1134,7 @@ public function key()
*
* @return boolean FALSE if there's nothing more to iterate over
*/
public function valid()
public function valid(): bool
{
return $this -> Valid;
}
Expand All @@ -1144,7 +1144,7 @@ public function valid()
* Ostensibly should return the count of the contained items but this just returns the number
* of rows read so far. It's not really correct but at least coherent.
*/
public function count()
public function count(): int
{
return $this -> Index + 1;
}
Expand Down