Skip to content

Commit 071b8bf

Browse files
authored
Merge pull request #266 from Tybaze/compat_php8.1
Ensure compatibility with PHP 8.0 & 8.1
2 parents d0e631d + 1e9b188 commit 071b8bf

File tree

67 files changed

+515
-115
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+515
-115
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: "Continuous Integration"
22

3-
on: [push]
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
48

59
env:
610
fail-fast: true
@@ -14,8 +18,8 @@ jobs:
1418
matrix:
1519
php-version:
1620
- "7.4"
17-
# - "8.0"
18-
# - "8.1"
21+
- "8.0"
22+
- "8.1"
1923
memcached-version:
2024
- "1.6"
2125

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ All the enhancements and BC breaks are listed in the [WHATS_NEW](https://github.
1111

1212
- [DIC](https://github.com/FriendsOfSymfony1/symfony1/wiki/ServiceContainer)
1313
- Composer support
14-
- PHP 7.2 support
14+
- PHP 8.1 support
1515
- performance boost
1616
- new widgets & validators
1717
- some tickets fixed from the symfony trac

lib/addon/sfPager.class.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ protected function resetIterator()
529529
*
530530
* @see Iterator
531531
*/
532+
#[\ReturnTypeWillChange]
532533
public function current()
533534
{
534535
if (!$this->isIteratorInitialized())
@@ -544,6 +545,7 @@ public function current()
544545
*
545546
* @see Iterator
546547
*/
548+
#[\ReturnTypeWillChange]
547549
public function key()
548550
{
549551
if (!$this->isIteratorInitialized())
@@ -559,6 +561,7 @@ public function key()
559561
*
560562
* @see Iterator
561563
*/
564+
#[\ReturnTypeWillChange]
562565
public function next()
563566
{
564567
if (!$this->isIteratorInitialized())
@@ -576,6 +579,7 @@ public function next()
576579
*
577580
* @see Iterator
578581
*/
582+
#[\ReturnTypeWillChange]
579583
public function rewind()
580584
{
581585
if (!$this->isIteratorInitialized())
@@ -593,6 +597,7 @@ public function rewind()
593597
*
594598
* @see Iterator
595599
*/
600+
#[\ReturnTypeWillChange]
596601
public function valid()
597602
{
598603
if (!$this->isIteratorInitialized())
@@ -608,6 +613,7 @@ public function valid()
608613
*
609614
* @see Countable
610615
*/
616+
#[\ReturnTypeWillChange]
611617
public function count()
612618
{
613619
return $this->getNbResults();

lib/cache/sfFileCache.class.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,15 @@ protected function read($path, $type = self::READ_DATA)
256256
fseek($fp, 0, SEEK_END);
257257
$length = ftell($fp) - 24;
258258
fseek($fp, 24);
259-
$data[self::READ_DATA] = @fread($fp, $length);
259+
260+
if ($length > 0)
261+
{
262+
$data[self::READ_DATA] = @fread($fp, $length);
263+
}
264+
else
265+
{
266+
$data[self::READ_DATA] = '';
267+
}
260268
}
261269
}
262270
else

lib/database/sfMySQLiDatabase.class.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@
1818
class sfMySQLiDatabase extends sfMySQLDatabase
1919
{
2020

21+
/**
22+
* @return void
23+
* @throws sfDatabaseException
24+
*/
25+
public function connect()
26+
{
27+
// PHP 8.1 Activate Exception per default, revert behavior to "return false"
28+
mysqli_report(MYSQLI_REPORT_OFF);
29+
30+
parent::connect();
31+
}
32+
2133
/**
2234
* Returns the appropriate connect method.
2335
*

lib/escaper/sfOutputEscaperArrayDecorator.class.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function __construct($escapingMethod, $value)
4242
/**
4343
* Reset the array to the beginning (as required for the Iterator interface).
4444
*/
45+
#[\ReturnTypeWillChange]
4546
public function rewind()
4647
{
4748
reset($this->value);
@@ -54,6 +55,7 @@ public function rewind()
5455
*
5556
* @return string The key
5657
*/
58+
#[\ReturnTypeWillChange]
5759
public function key()
5860
{
5961
return key($this->value);
@@ -67,6 +69,7 @@ public function key()
6769
*
6870
* @return mixed The escaped value
6971
*/
72+
#[\ReturnTypeWillChange]
7073
public function current()
7174
{
7275
return sfOutputEscaper::escape($this->escapingMethod, current($this->value));
@@ -75,6 +78,7 @@ public function current()
7578
/**
7679
* Moves to the next element (as required by the Iterator interface).
7780
*/
81+
#[\ReturnTypeWillChange]
7882
public function next()
7983
{
8084
next($this->value);
@@ -91,6 +95,7 @@ public function next()
9195
*
9296
* @return bool The validity of the current element; true if it is valid
9397
*/
98+
#[\ReturnTypeWillChange]
9499
public function valid()
95100
{
96101
return $this->count > 0;
@@ -103,6 +108,7 @@ public function valid()
103108
*
104109
* @return bool true if the offset isset; false otherwise
105110
*/
111+
#[\ReturnTypeWillChange]
106112
public function offsetExists($offset)
107113
{
108114
return isset($this->value[$offset]);
@@ -115,6 +121,7 @@ public function offsetExists($offset)
115121
*
116122
* @return mixed The escaped value
117123
*/
124+
#[\ReturnTypeWillChange]
118125
public function offsetGet($offset)
119126
{
120127
return sfOutputEscaper::escape($this->escapingMethod, $this->value[$offset]);
@@ -132,6 +139,7 @@ public function offsetGet($offset)
132139
*
133140
* @throws sfException
134141
*/
142+
#[\ReturnTypeWillChange]
135143
public function offsetSet($offset, $value)
136144
{
137145
throw new sfException('Cannot set values.');
@@ -148,6 +156,7 @@ public function offsetSet($offset, $value)
148156
*
149157
* @throws sfException
150158
*/
159+
#[\ReturnTypeWillChange]
151160
public function offsetUnset($offset)
152161
{
153162
throw new sfException('Cannot unset values.');
@@ -158,6 +167,7 @@ public function offsetUnset($offset)
158167
*
159168
* @return int The size of the array
160169
*/
170+
#[\ReturnTypeWillChange]
161171
public function count()
162172
{
163173
return count($this->value);

lib/escaper/sfOutputEscaperIteratorDecorator.class.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public function __construct($escapingMethod, Traversable $value)
5656
*
5757
* @return void
5858
*/
59+
#[\ReturnTypeWillChange]
5960
public function rewind()
6061
{
6162
return $this->iterator->rewind();
@@ -66,6 +67,7 @@ public function rewind()
6667
*
6768
* @return mixed The escaped value
6869
*/
70+
#[\ReturnTypeWillChange]
6971
public function current()
7072
{
7173
return sfOutputEscaper::escape($this->escapingMethod, $this->iterator->current());
@@ -76,6 +78,7 @@ public function current()
7678
*
7779
* @return string Iterator key
7880
*/
81+
#[\ReturnTypeWillChange]
7982
public function key()
8083
{
8184
return $this->iterator->key();
@@ -86,6 +89,7 @@ public function key()
8689
*
8790
* @return void
8891
*/
92+
#[\ReturnTypeWillChange]
8993
public function next()
9094
{
9195
return $this->iterator->next();
@@ -97,6 +101,7 @@ public function next()
97101
*
98102
* @return bool true if the current element is valid; false otherwise
99103
*/
104+
#[\ReturnTypeWillChange]
100105
public function valid()
101106
{
102107
return $this->iterator->valid();
@@ -109,6 +114,7 @@ public function valid()
109114
*
110115
* @return bool true if the offset isset; false otherwise
111116
*/
117+
#[\ReturnTypeWillChange]
112118
public function offsetExists($offset)
113119
{
114120
return isset($this->value[$offset]);
@@ -121,6 +127,7 @@ public function offsetExists($offset)
121127
*
122128
* @return mixed The escaped value
123129
*/
130+
#[\ReturnTypeWillChange]
124131
public function offsetGet($offset)
125132
{
126133
return sfOutputEscaper::escape($this->escapingMethod, $this->value[$offset]);
@@ -138,6 +145,7 @@ public function offsetGet($offset)
138145
*
139146
* @throws sfException
140147
*/
148+
#[\ReturnTypeWillChange]
141149
public function offsetSet($offset, $value)
142150
{
143151
throw new sfException('Cannot set values.');
@@ -154,6 +162,7 @@ public function offsetSet($offset, $value)
154162
*
155163
* @throws sfException
156164
*/
165+
#[\ReturnTypeWillChange]
157166
public function offsetUnset($offset)
158167
{
159168
throw new sfException('Cannot unset values.');

lib/escaper/sfOutputEscaperObjectDecorator.class.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,18 @@ public function __isset($key)
111111
/**
112112
* Returns the size of the object if it implements Countable (is required by the Countable interface).
113113
*
114-
* It returns 1 if other cases (which is the default PHP behavior in such a case).
114+
* It returns 1 if other cases (which was the default PHP behavior in such a case before php 7.3).
115115
*
116116
* @return int The size of the object
117117
*/
118+
#[\ReturnTypeWillChange]
118119
public function count()
119120
{
120-
return count($this->value);
121+
// See https://github.com/symfony/polyfill/commit/d330c0094a47d8edceeea1ed553d6e08215a9fc2
122+
if (is_array($this->value) || $this->value instanceof Countable || $this->value instanceof ResourceBundle || $this->value instanceof SimpleXmlElement)
123+
{
124+
return count($this->value);
125+
}
126+
return 1;
121127
}
122128
}

lib/event/sfEvent.class.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function getReturnValue()
8383
/**
8484
* Sets the processed flag.
8585
*
86-
* @param Boolean $processed The processed flag value
86+
* @param bool $processed The processed flag value
8787
*/
8888
public function setProcessed($processed)
8989
{
@@ -117,6 +117,7 @@ public function getParameters()
117117
*
118118
* @return Boolean true if the parameter exists, false otherwise
119119
*/
120+
#[\ReturnTypeWillChange]
120121
public function offsetExists($name)
121122
{
122123
return array_key_exists($name, $this->parameters);
@@ -129,6 +130,7 @@ public function offsetExists($name)
129130
*
130131
* @return mixed The parameter value
131132
*/
133+
#[\ReturnTypeWillChange]
132134
public function offsetGet($name)
133135
{
134136
if (!array_key_exists($name, $this->parameters))
@@ -145,6 +147,7 @@ public function offsetGet($name)
145147
* @param string $name The parameter name
146148
* @param mixed $value The parameter value
147149
*/
150+
#[\ReturnTypeWillChange]
148151
public function offsetSet($name, $value)
149152
{
150153
$this->parameters[$name] = $value;
@@ -155,6 +158,7 @@ public function offsetSet($name, $value)
155158
*
156159
* @param string $name The parameter name
157160
*/
161+
#[\ReturnTypeWillChange]
158162
public function offsetUnset($name)
159163
{
160164
unset($this->parameters[$name]);

lib/exception/sfException.class.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,12 @@ static protected function formatArrayAsHtml($values)
366366
*/
367367
static protected function fileExcerpt($file, $line)
368368
{
369+
// $file can be null for RuntimeException
370+
if (null === $file)
371+
{
372+
return '';
373+
}
374+
369375
if (is_readable($file))
370376
{
371377
$content = preg_split('#<br />#', preg_replace('/^<code>(.*)<\/code>$/s', '$1', highlight_file($file, true)));

0 commit comments

Comments
 (0)