Bugs in PHP 8.2
Bugs in PHP 8.2
rdueck
Posts: 12Questions: 2Answers: 0
Link to test case:
Debugger code (debug.datatables.net):
Error messages shown: A system error has occurred (More information).
Description of problem: Submitting changes from an Editor dialog fails (tested for "Update"). Server-side error messages with the PHP API are as follows when using PHP 8.2:
PHP Deprecated: Creation of dynamic property DataTables\\Database::$type is deprecated in editor-php-2.0.10/lib/Database.php on line 62
PHP Deprecated: Creation of dynamic property DataTables\\Database::$query_driver is deprecated in editor-php-2.0.10/lib/Database.php on line 63
PHP Deprecated: Use of "self" in callables is deprecated in editor-php-2.0.10/lib/HtmLawed/Htmlawed.php on line 101
PHP Deprecated: Use of "self" in callables is deprecated in editor-php-2.0.10/lib/HtmLawed/Htmlawed.php on line 102
PHP Deprecated: Use of "self" in callables is deprecated in editor-php-2.0.10/lib/HtmLawed/Htmlawed.php on line 109
The following patches resolve these problems.
1) Declare class properties as required by PHP 8.2
diff --git a/lib/Database.php b/lib/Database.php
index b6c27f8..67363cf 100644
--- a/lib/Database.php
+++ b/lib/Database.php
@@ -30,6 +30,9 @@ use
* methods.
*/
class Database {
+ public $type;
+ private $query_driver;
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Constructor
*/
diff --git a/lib/Database/Query.php b/lib/Database/Query.php
index 98e1b89..a740096 100644
--- a/lib/Database/Query.php
+++ b/lib/Database/Query.php
@@ -37,6 +37,8 @@ use
* same for all database types.
*/
abstract class Query {
+ private $_dbHost;
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Constructor
*/
2) Revise callables as required by PHP 8.2
diff --git a/lib/HtmLawed/Htmlawed.php b/lib/HtmLawed/Htmlawed.php
index f4c2604..64c37af 100644
--- a/lib/HtmLawed/Htmlawed.php
+++ b/lib/HtmLawed/Htmlawed.php
@@ -98,15 +98,15 @@ if($C['clean_ms_char']){
$x = $x + ($C['clean_ms_char'] == 1 ? array("\x82"=>'‚', "\x84"=>'„', "\x91"=>'‘', "\x92"=>'’', "\x93"=>'“', "\x94"=>'”') : array("\x82"=>'\'', "\x84"=>'"', "\x91"=>'\'', "\x92"=>'\'', "\x93"=>'"', "\x94"=>'"'));
$t = strtr($t, $x);
}
-if($C['cdata'] or $C['comment']){$t = preg_replace_callback('`<!(?:(?:--.*?--)|(?:\[CDATA\[.*?\]\]))>`sm', 'self::hl_cmtcd', $t);}
-$t = preg_replace_callback('`&([a-zA-Z][a-zA-Z0-9]{1,30}|#(?:[0-9]{1,8}|[Xx][0-9A-Fa-f]{1,7}));`', 'self::hl_ent', str_replace('&', '&', $t));
+if($C['cdata'] or $C['comment']){$t = preg_replace_callback('`<!(?:(?:--.*?--)|(?:\[CDATA\[.*?\]\]))>`sm', 'DataTables\HtmLawed\Htmlawed::hl_cmtcd', $t);}
+$t = preg_replace_callback('`&([a-zA-Z][a-zA-Z0-9]{1,30}|#(?:[0-9]{1,8}|[Xx][0-9A-Fa-f]{1,7}));`', 'DataTables\HtmLawed\Htmlawed::hl_ent', str_replace('&', '&', $t));
if($C['unique_ids'] && !isset($GLOBALS['hl_Ids'])){$GLOBALS['hl_Ids'] = array();}
if($C['hook']){$t = $C['hook']($t, $C, $S);}
if($C['show_setting'] && preg_match('`^[a-z][a-z0-9_]*$`i', $C['show_setting'])){
$GLOBALS[$C['show_setting']] = array('config'=>$C, 'spec'=>$S, 'time'=>microtime());
}
// main
-$t = preg_replace_callback('`<(?:(?:\s|$)|(?:[^>]*(?:>|$)))|>`m', 'self::hl_tag', $t);
+$t = preg_replace_callback('`<(?:(?:\s|$)|(?:[^>]*(?:>|$)))|>`m', 'DataTables\HtmLawed\Htmlawed::hl_tag', $t);
$t = $C['balance'] ? self::hl_bal($t, $C['keep_bad'], $C['parent']) : $t;
$t = (($C['cdata'] or $C['comment']) && strpos($t, "\x01") !== false) ? str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05"), array('', '', '&', '<', '>'), $t) : $t;
$t = $C['tidy'] ? self::hl_tidy($t, $C['tidy'], $C['parent']) : $t;
@@ -518,7 +518,7 @@ foreach($aA as $k=>$v){
static $sC = array(' '=>' ', ' '=>' ', 'E'=>'e', 'E'=>'e', 'e'=>'e', 'e'=>'e', 'X'=>'x', 'X'=>'x', 'x'=>'x', 'x'=>'x', 'P'=>'p', 'P'=>'p', 'p'=>'p', 'p'=>'p', 'S'=>'s', 'S'=>'s', 's'=>'s', 's'=>'s', 'I'=>'i', 'I'=>'i', 'i'=>'i', 'i'=>'i', 'O'=>'o', 'O'=>'o', 'o'=>'o', 'o'=>'o', 'N'=>'n', 'N'=>'n', 'n'=>'n', 'n'=>'n', 'U'=>'u', 'U'=>'u', 'u'=>'u', 'u'=>'u', 'R'=>'r', 'R'=>'r', 'r'=>'r', 'r'=>'r', 'L'=>'l', 'L'=>'l', 'l'=>'l', 'l'=>'l', '('=>'(', '('=>'(', ')'=>')', ')'=>')', ' '=>':', ' '=>':', '"'=>'"', '"'=>'"', '''=>"'", '''=>"'", '/'=>'/', '/'=>'/', '*'=>'*', '*'=>'*', '\'=>'\\', '\'=>'\\');
$v = strtr($v, $sC);
}
- $v = preg_replace_callback('`(url(?:\()(?: )*(?:\'|"|&(?:quot|apos);)?)(.+?)((?:\'|"|&(?:quot|apos);)?(?: )*(?:\)))`iS', 'self::hl_prot', $v);
+ $v = preg_replace_callback('`(url(?:\()(?: )*(?:\'|"|&(?:quot|apos);)?)(.+?)((?:\'|"|&(?:quot|apos);)?(?: )*(?:\)))`iS', 'DataTables\HtmLawed\Htmlawed::hl_prot', $v);
$v = !$C['css_expression'] ? preg_replace('`expression`i', ' ', preg_replace('`\\\\\S|(/|(%2f))(\*|(%2a))`i', ' ', $v)) : $v;
}elseif(isset($aNP[$k]) or isset($aNO[$k])){
$v = str_replace("", ' ', (strpos($v, '&') !== false ? str_replace(array('­', '­', '­'), ' ', $v) : $v)); # double-quoted char: soft-hyphen; appears here as "" or hyphen or something else depending on viewing software
Replies
Many thanks for flagging this up. I've committed a change here for the DataTable.php issue (I think they should both be private properties - the type is not expected to be settable).
I've updated Htmlawed recently which will hopefully address the issue there, but I'll check tomorrow. I need to update my box for PHP 8.2
Regards,
Allan
I set both to
private
initially, but got an error and switched it topublic
:Agreed! Fix committed here.
Allan
How can I apply this fix easily before a new official build is out? I tried changing some of those lines/files but couldn't get it to work. What would you suggest?
Option 1 - Download the code from the repo and put it into where you currently have the Editor PHP libraries - i.e. just replace the existing code you have with the new stuff. Not the config.php file - you'll want to keep your own one for the database connection.
Option 2 - For smaller changes, grab the source from the files and just whole sale copy / paste the file.
Allan
Thank Allan I got it! I think last time I accidentally didn't put it into lib folder I put it one up. After putting it into lib it works!