Skip to content

Commit

Permalink
Merge pull request #266 from Tybaze/compat_php8.1
Browse files Browse the repository at this point in the history
Ensure compatibility with PHP 8.0 & 8.1
  • Loading branch information
thePanz authored Nov 25, 2022
2 parents d0e631d + 1e9b188 commit 071b8bf
Show file tree
Hide file tree
Showing 67 changed files with 515 additions and 115 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: "Continuous Integration"

on: [push]
on:
push:
branches:
- master
pull_request:

env:
fail-fast: true
Expand All @@ -14,8 +18,8 @@ jobs:
matrix:
php-version:
- "7.4"
# - "8.0"
# - "8.1"
- "8.0"
- "8.1"
memcached-version:
- "1.6"

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ All the enhancements and BC breaks are listed in the [WHATS_NEW](https://github.

- [DIC](https://github.com/FriendsOfSymfony1/symfony1/wiki/ServiceContainer)
- Composer support
- PHP 7.2 support
- PHP 8.1 support
- performance boost
- new widgets & validators
- some tickets fixed from the symfony trac
Expand Down
6 changes: 6 additions & 0 deletions lib/addon/sfPager.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ protected function resetIterator()
*
* @see Iterator
*/
#[\ReturnTypeWillChange]
public function current()
{
if (!$this->isIteratorInitialized())
Expand All @@ -544,6 +545,7 @@ public function current()
*
* @see Iterator
*/
#[\ReturnTypeWillChange]
public function key()
{
if (!$this->isIteratorInitialized())
Expand All @@ -559,6 +561,7 @@ public function key()
*
* @see Iterator
*/
#[\ReturnTypeWillChange]
public function next()
{
if (!$this->isIteratorInitialized())
Expand All @@ -576,6 +579,7 @@ public function next()
*
* @see Iterator
*/
#[\ReturnTypeWillChange]
public function rewind()
{
if (!$this->isIteratorInitialized())
Expand All @@ -593,6 +597,7 @@ public function rewind()
*
* @see Iterator
*/
#[\ReturnTypeWillChange]
public function valid()
{
if (!$this->isIteratorInitialized())
Expand All @@ -608,6 +613,7 @@ public function valid()
*
* @see Countable
*/
#[\ReturnTypeWillChange]
public function count()
{
return $this->getNbResults();
Expand Down
10 changes: 9 additions & 1 deletion lib/cache/sfFileCache.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,15 @@ protected function read($path, $type = self::READ_DATA)
fseek($fp, 0, SEEK_END);
$length = ftell($fp) - 24;
fseek($fp, 24);
$data[self::READ_DATA] = @fread($fp, $length);

if ($length > 0)
{
$data[self::READ_DATA] = @fread($fp, $length);
}
else
{
$data[self::READ_DATA] = '';
}
}
}
else
Expand Down
12 changes: 12 additions & 0 deletions lib/database/sfMySQLiDatabase.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
class sfMySQLiDatabase extends sfMySQLDatabase
{

/**
* @return void
* @throws sfDatabaseException
*/
public function connect()
{
// PHP 8.1 Activate Exception per default, revert behavior to "return false"
mysqli_report(MYSQLI_REPORT_OFF);

parent::connect();
}

/**
* Returns the appropriate connect method.
*
Expand Down
10 changes: 10 additions & 0 deletions lib/escaper/sfOutputEscaperArrayDecorator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function __construct($escapingMethod, $value)
/**
* Reset the array to the beginning (as required for the Iterator interface).
*/
#[\ReturnTypeWillChange]
public function rewind()
{
reset($this->value);
Expand All @@ -54,6 +55,7 @@ public function rewind()
*
* @return string The key
*/
#[\ReturnTypeWillChange]
public function key()
{
return key($this->value);
Expand All @@ -67,6 +69,7 @@ public function key()
*
* @return mixed The escaped value
*/
#[\ReturnTypeWillChange]
public function current()
{
return sfOutputEscaper::escape($this->escapingMethod, current($this->value));
Expand All @@ -75,6 +78,7 @@ public function current()
/**
* Moves to the next element (as required by the Iterator interface).
*/
#[\ReturnTypeWillChange]
public function next()
{
next($this->value);
Expand All @@ -91,6 +95,7 @@ public function next()
*
* @return bool The validity of the current element; true if it is valid
*/
#[\ReturnTypeWillChange]
public function valid()
{
return $this->count > 0;
Expand All @@ -103,6 +108,7 @@ public function valid()
*
* @return bool true if the offset isset; false otherwise
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return isset($this->value[$offset]);
Expand All @@ -115,6 +121,7 @@ public function offsetExists($offset)
*
* @return mixed The escaped value
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return sfOutputEscaper::escape($this->escapingMethod, $this->value[$offset]);
Expand All @@ -132,6 +139,7 @@ public function offsetGet($offset)
*
* @throws sfException
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
throw new sfException('Cannot set values.');
Expand All @@ -148,6 +156,7 @@ public function offsetSet($offset, $value)
*
* @throws sfException
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
throw new sfException('Cannot unset values.');
Expand All @@ -158,6 +167,7 @@ public function offsetUnset($offset)
*
* @return int The size of the array
*/
#[\ReturnTypeWillChange]
public function count()
{
return count($this->value);
Expand Down
9 changes: 9 additions & 0 deletions lib/escaper/sfOutputEscaperIteratorDecorator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function __construct($escapingMethod, Traversable $value)
*
* @return void
*/
#[\ReturnTypeWillChange]
public function rewind()
{
return $this->iterator->rewind();
Expand All @@ -66,6 +67,7 @@ public function rewind()
*
* @return mixed The escaped value
*/
#[\ReturnTypeWillChange]
public function current()
{
return sfOutputEscaper::escape($this->escapingMethod, $this->iterator->current());
Expand All @@ -76,6 +78,7 @@ public function current()
*
* @return string Iterator key
*/
#[\ReturnTypeWillChange]
public function key()
{
return $this->iterator->key();
Expand All @@ -86,6 +89,7 @@ public function key()
*
* @return void
*/
#[\ReturnTypeWillChange]
public function next()
{
return $this->iterator->next();
Expand All @@ -97,6 +101,7 @@ public function next()
*
* @return bool true if the current element is valid; false otherwise
*/
#[\ReturnTypeWillChange]
public function valid()
{
return $this->iterator->valid();
Expand All @@ -109,6 +114,7 @@ public function valid()
*
* @return bool true if the offset isset; false otherwise
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return isset($this->value[$offset]);
Expand All @@ -121,6 +127,7 @@ public function offsetExists($offset)
*
* @return mixed The escaped value
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return sfOutputEscaper::escape($this->escapingMethod, $this->value[$offset]);
Expand All @@ -138,6 +145,7 @@ public function offsetGet($offset)
*
* @throws sfException
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
throw new sfException('Cannot set values.');
Expand All @@ -154,6 +162,7 @@ public function offsetSet($offset, $value)
*
* @throws sfException
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
throw new sfException('Cannot unset values.');
Expand Down
10 changes: 8 additions & 2 deletions lib/escaper/sfOutputEscaperObjectDecorator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,18 @@ public function __isset($key)
/**
* Returns the size of the object if it implements Countable (is required by the Countable interface).
*
* It returns 1 if other cases (which is the default PHP behavior in such a case).
* It returns 1 if other cases (which was the default PHP behavior in such a case before php 7.3).
*
* @return int The size of the object
*/
#[\ReturnTypeWillChange]
public function count()
{
return count($this->value);
// See https://github.com/symfony/polyfill/commit/d330c0094a47d8edceeea1ed553d6e08215a9fc2
if (is_array($this->value) || $this->value instanceof Countable || $this->value instanceof ResourceBundle || $this->value instanceof SimpleXmlElement)
{
return count($this->value);
}
return 1;
}
}
6 changes: 5 additions & 1 deletion lib/event/sfEvent.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function getReturnValue()
/**
* Sets the processed flag.
*
* @param Boolean $processed The processed flag value
* @param bool $processed The processed flag value
*/
public function setProcessed($processed)
{
Expand Down Expand Up @@ -117,6 +117,7 @@ public function getParameters()
*
* @return Boolean true if the parameter exists, false otherwise
*/
#[\ReturnTypeWillChange]
public function offsetExists($name)
{
return array_key_exists($name, $this->parameters);
Expand All @@ -129,6 +130,7 @@ public function offsetExists($name)
*
* @return mixed The parameter value
*/
#[\ReturnTypeWillChange]
public function offsetGet($name)
{
if (!array_key_exists($name, $this->parameters))
Expand All @@ -145,6 +147,7 @@ public function offsetGet($name)
* @param string $name The parameter name
* @param mixed $value The parameter value
*/
#[\ReturnTypeWillChange]
public function offsetSet($name, $value)
{
$this->parameters[$name] = $value;
Expand All @@ -155,6 +158,7 @@ public function offsetSet($name, $value)
*
* @param string $name The parameter name
*/
#[\ReturnTypeWillChange]
public function offsetUnset($name)
{
unset($this->parameters[$name]);
Expand Down
6 changes: 6 additions & 0 deletions lib/exception/sfException.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,12 @@ static protected function formatArrayAsHtml($values)
*/
static protected function fileExcerpt($file, $line)
{
// $file can be null for RuntimeException
if (null === $file)
{
return '';
}

if (is_readable($file))
{
$content = preg_split('#<br />#', preg_replace('/^<code>(.*)<\/code>$/s', '$1', highlight_file($file, true)));
Expand Down
Loading

0 comments on commit 071b8bf

Please sign in to comment.