Skip to content

Commit d860ebf

Browse files
opengeekjenswittmann
authored andcommitted
PHP 8.4 compatibility updates (modxcms#16654)
### What does it do? Removes usage of deprecated features and updates dependencies with available PHP8.4 compatibility releases. ### Why is it needed? Resolves various deprecation warnings for PHP 8.4 compatibility. ### How to test Test everything (including unit tests) in PHP 8.4 ### Related issue(s)/PR(s) Port of modxcms#16648 for 3.x branch
1 parent 770444c commit d860ebf

File tree

9 files changed

+23
-17
lines changed

9 files changed

+23
-17
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333

3434
strategy:
3535
matrix:
36-
php-version: ['7.4', '8.0', '8.1', '8.2']
36+
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
3737

3838
steps:
3939
- name: Checkout

_build/lexicon/checklexicon.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/* get rid of time limit */
1515
set_time_limit(0);
1616

17-
error_reporting(E_ALL | E_STRICT);
17+
error_reporting(E_ALL);
1818
ini_set('display_errors', true);
1919

2020
$buildConfig = dirname(dirname(__FILE__)) . '/build.config.php';

_build/transport.core.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/* get rid of time limit */
1313
set_time_limit(0);
1414

15-
error_reporting(E_ALL | E_STRICT);
15+
error_reporting(E_ALL);
1616
ini_set('display_errors', true);
1717

1818
/* buildImage can be defined for running against a specific build image

core/src/Revolution/Error/modErrorHandler.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class modErrorHandler
3737
* @param array $stack A stack of errors that can be passed in. Send a non-array value to
3838
* prevent any errors from being recorded in the stack.
3939
*/
40-
function __construct(modX &$modx, array $stack = [])
40+
public function __construct(modX &$modx, array $stack = [])
4141
{
4242
$this->modx = &$modx;
4343
$this->stack = $stack;
@@ -94,13 +94,6 @@ public function handleError($errno, $errstr, $errfile = null, $errline = null, $
9494
$errmsg = 'User notice: ' . $errstr;
9595
$this->modx->log(modX::LOG_LEVEL_WARN, $errmsg, '', '', $errfile, $errline);
9696
break;
97-
case E_STRICT:
98-
$handled = true;
99-
$errmsg = 'E_STRICT information: ' . $errstr;
100-
$this->modx->log(modX::LOG_LEVEL_INFO, $errmsg, '', '', $errfile, $errline);
101-
102-
return $handled;
103-
break;
10497
case E_RECOVERABLE_ERROR:
10598
$handled = true;
10699
$errmsg = 'Recoverable error: ' . $errstr;
@@ -117,6 +110,13 @@ public function handleError($errno, $errstr, $errfile = null, $errline = null, $
117110
$this->modx->log(modX::LOG_LEVEL_WARN, $errmsg, '', '', $errfile, $errline);
118111
break;
119112
default:
113+
if (version_compare(PHP_VERSION, '8.4.0', '<') && $errno == E_STRICT) {
114+
$handled = true;
115+
$errmsg = 'E_STRICT information: ' . $errstr;
116+
$this->modx->log(modX::LOG_LEVEL_INFO, $errmsg, '', '', $errfile, $errline);
117+
break;
118+
}
119+
120120
$handled = false;
121121
$errmsg = 'Un-recoverable error ' . $errno . ': ' . $errstr;
122122
$this->modx->log(modX::LOG_LEVEL_ERROR, $errmsg, '', '', $errfile, $errline);

core/src/Revolution/Sources/modMediaSource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,11 +1696,11 @@ public function findPolicy($context = '')
16961696
*
16971697
* @param string|array $criteria
16981698
* @param array $targets
1699-
* @param modUser $user
1699+
* @param modUser|null $user
17001700
*
17011701
* @return bool
17021702
*/
1703-
public function checkPolicy($criteria, $targets = null, modUser $user = null)
1703+
public function checkPolicy($criteria, $targets = null, ?modUser $user = null)
17041704
{
17051705
if ($criteria == 'load') {
17061706
$success = true;

core/src/Revolution/modAccessibleObject.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,12 @@ public function remove(array $ancestors = [])
242242
* class names to limit the check. In most cases, this does not need to be
243243
* set; derivatives should typically determine what targets to include in
244244
* the findPolicy() implementation.
245-
* @param modUser $user
245+
* @param modUser|null $user
246246
*
247247
* @return boolean Returns true if the policy is satisfied or no policy
248248
* exists.
249249
*/
250-
public function checkPolicy($criteria, $targets = null, modUser $user = null)
250+
public function checkPolicy($criteria, $targets = null, ?modUser $user = null)
251251
{
252252
if ($criteria && $this->xpdo instanceof modX && $this->xpdo->getSessionState() == modX::SESSION_STATE_INITIALIZED) {
253253
if (!$user) {

core/src/Revolution/modDeprecatedMethod.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class modDeprecatedMethod extends \xPDO\Om\xPDOSimpleObject
1717
{
1818
private $callers = [];
1919

20-
public function addCaller(string $class, string $function, string $file = null, int $line = null)
20+
public function addCaller(string $class, string $function, ?string $file = null, ?int $line = null)
2121
{
2222
$def = "{$class}::{$function}::{$file}::{$line}";
2323

core/src/Revolution/modNamespace.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public static function translatePath(xPDO &$xpdo, $path)
108108
], $path);
109109
}
110110

111-
public function checkPolicy($criteria, $targets = null, modUser $user = null)
111+
public function checkPolicy($criteria, $targets = null, ?modUser $user = null)
112112
{
113113
return parent::checkPolicy($criteria, $targets, $user);
114114
}

core/src/Revolution/modSessionHandler.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public function __construct(modX &$modx)
6868
* @return boolean Always returns true; actual connection is managed by
6969
* {@link modX}.
7070
*/
71+
#[\ReturnTypeWillChange]
7172
public function open($path, $name)
7273
{
7374
return true;
@@ -80,6 +81,7 @@ public function open($path, $name)
8081
* @return boolean Always returns true; actual connection is managed by
8182
* {@link modX}
8283
*/
84+
#[\ReturnTypeWillChange]
8385
public function close()
8486
{
8587
return true;
@@ -94,6 +96,7 @@ public function close()
9496
*
9597
* @return string The data read from the {@link modSession} object.
9698
*/
99+
#[\ReturnTypeWillChange]
97100
public function read($id)
98101
{
99102
if ($this->_getSession($id)) {
@@ -115,6 +118,7 @@ public function read($id)
115118
*
116119
* @return boolean True if successfully written.
117120
*/
121+
#[\ReturnTypeWillChange]
118122
public function write($id, $data)
119123
{
120124
$written = false;
@@ -138,6 +142,7 @@ public function write($id, $data)
138142
*
139143
* @return boolean True if the session record was destroyed.
140144
*/
145+
#[\ReturnTypeWillChange]
141146
public function destroy($id)
142147
{
143148
if ($this->_getSession($id)) {
@@ -159,6 +164,7 @@ public function destroy($id)
159164
*
160165
* @return boolean True if session records were removed.
161166
*/
167+
#[\ReturnTypeWillChange]
162168
public function gc($max)
163169
{
164170
$maxtime = time() - $this->gcMaxLifetime;

0 commit comments

Comments
 (0)