Skip to content

Commit

Permalink
PHP 8.4 compatibility updates (#16654)
Browse files Browse the repository at this point in the history
### 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 #16648 for 3.x branch
  • Loading branch information
opengeek authored Dec 3, 2024
1 parent ed2b5b7 commit 845d568
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:

strategy:
matrix:
php-version: ['7.4', '8.0', '8.1', '8.2']
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4']

steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion _build/lexicon/checklexicon.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/* get rid of time limit */
set_time_limit(0);

error_reporting(E_ALL | E_STRICT);
error_reporting(E_ALL);
ini_set('display_errors', true);

$buildConfig = dirname(dirname(__FILE__)) . '/build.config.php';
Expand Down
2 changes: 1 addition & 1 deletion _build/transport.core.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/* get rid of time limit */
set_time_limit(0);

error_reporting(E_ALL | E_STRICT);
error_reporting(E_ALL);
ini_set('display_errors', true);

/* buildImage can be defined for running against a specific build image
Expand Down
16 changes: 8 additions & 8 deletions core/src/Revolution/Error/modErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class modErrorHandler
* @param array $stack A stack of errors that can be passed in. Send a non-array value to
* prevent any errors from being recorded in the stack.
*/
function __construct(modX &$modx, array $stack = [])
public function __construct(modX &$modx, array $stack = [])
{
$this->modx = &$modx;
$this->stack = $stack;
Expand Down Expand Up @@ -94,13 +94,6 @@ public function handleError($errno, $errstr, $errfile = null, $errline = null, $
$errmsg = 'User notice: ' . $errstr;
$this->modx->log(modX::LOG_LEVEL_WARN, $errmsg, '', '', $errfile, $errline);
break;
case E_STRICT:
$handled = true;
$errmsg = 'E_STRICT information: ' . $errstr;
$this->modx->log(modX::LOG_LEVEL_INFO, $errmsg, '', '', $errfile, $errline);

return $handled;
break;
case E_RECOVERABLE_ERROR:
$handled = true;
$errmsg = 'Recoverable error: ' . $errstr;
Expand All @@ -117,6 +110,13 @@ public function handleError($errno, $errstr, $errfile = null, $errline = null, $
$this->modx->log(modX::LOG_LEVEL_WARN, $errmsg, '', '', $errfile, $errline);
break;
default:
if (version_compare(PHP_VERSION, '8.4.0', '<') && $errno == E_STRICT) {
$handled = true;
$errmsg = 'E_STRICT information: ' . $errstr;
$this->modx->log(modX::LOG_LEVEL_INFO, $errmsg, '', '', $errfile, $errline);
break;
}

$handled = false;
$errmsg = 'Un-recoverable error ' . $errno . ': ' . $errstr;
$this->modx->log(modX::LOG_LEVEL_ERROR, $errmsg, '', '', $errfile, $errline);
Expand Down
4 changes: 2 additions & 2 deletions core/src/Revolution/Sources/modMediaSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -1696,11 +1696,11 @@ public function findPolicy($context = '')
*
* @param string|array $criteria
* @param array $targets
* @param modUser $user
* @param modUser|null $user
*
* @return bool
*/
public function checkPolicy($criteria, $targets = null, modUser $user = null)
public function checkPolicy($criteria, $targets = null, ?modUser $user = null)
{
if ($criteria == 'load') {
$success = true;
Expand Down
4 changes: 2 additions & 2 deletions core/src/Revolution/modAccessibleObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,12 @@ public function remove(array $ancestors = [])
* class names to limit the check. In most cases, this does not need to be
* set; derivatives should typically determine what targets to include in
* the findPolicy() implementation.
* @param modUser $user
* @param modUser|null $user
*
* @return boolean Returns true if the policy is satisfied or no policy
* exists.
*/
public function checkPolicy($criteria, $targets = null, modUser $user = null)
public function checkPolicy($criteria, $targets = null, ?modUser $user = null)
{
if ($criteria && $this->xpdo instanceof modX && $this->xpdo->getSessionState() == modX::SESSION_STATE_INITIALIZED) {
if (!$user) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/Revolution/modDeprecatedMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class modDeprecatedMethod extends \xPDO\Om\xPDOSimpleObject
{
private $callers = [];

public function addCaller(string $class, string $function, string $file = null, int $line = null)
public function addCaller(string $class, string $function, ?string $file = null, ?int $line = null)
{
$def = "{$class}::{$function}::{$file}::{$line}";

Expand Down
2 changes: 1 addition & 1 deletion core/src/Revolution/modNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static function translatePath(xPDO &$xpdo, $path)
], $path);
}

public function checkPolicy($criteria, $targets = null, modUser $user = null)
public function checkPolicy($criteria, $targets = null, ?modUser $user = null)
{
return parent::checkPolicy($criteria, $targets, $user);
}
Expand Down
6 changes: 6 additions & 0 deletions core/src/Revolution/modSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function __construct(modX &$modx)
* @return boolean Always returns true; actual connection is managed by
* {@link modX}.
*/
#[\ReturnTypeWillChange]
public function open($path, $name)
{
return true;
Expand All @@ -80,6 +81,7 @@ public function open($path, $name)
* @return boolean Always returns true; actual connection is managed by
* {@link modX}
*/
#[\ReturnTypeWillChange]
public function close()
{
return true;
Expand All @@ -94,6 +96,7 @@ public function close()
*
* @return string The data read from the {@link modSession} object.
*/
#[\ReturnTypeWillChange]
public function read($id)
{
if ($this->_getSession($id)) {
Expand All @@ -115,6 +118,7 @@ public function read($id)
*
* @return boolean True if successfully written.
*/
#[\ReturnTypeWillChange]
public function write($id, $data)
{
$written = false;
Expand All @@ -138,6 +142,7 @@ public function write($id, $data)
*
* @return boolean True if the session record was destroyed.
*/
#[\ReturnTypeWillChange]
public function destroy($id)
{
if ($this->_getSession($id)) {
Expand All @@ -159,6 +164,7 @@ public function destroy($id)
*
* @return boolean True if session records were removed.
*/
#[\ReturnTypeWillChange]
public function gc($max)
{
$maxtime = time() - $this->gcMaxLifetime;
Expand Down

0 comments on commit 845d568

Please sign in to comment.