Bugs in PHP 8.2

Bugs in PHP 8.2

rdueckrdueck 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('`&amp;([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('&', '&amp;', $t));
+if($C['cdata'] or $C['comment']){$t = preg_replace_callback('`<!(?:(?:--.*?--)|(?:\[CDATA\[.*?\]\]))>`sm', 'DataTables\HtmLawed\Htmlawed::hl_cmtcd', $t);}
+$t = preg_replace_callback('`&amp;([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('&', '&amp;', $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('&#x20;'=>' ', '&#32;'=>' ', '&#x45;'=>'e', '&#69;'=>'e', '&#x65;'=>'e', '&#101;'=>'e', '&#x58;'=>'x', '&#88;'=>'x', '&#x78;'=>'x', '&#120;'=>'x', '&#x50;'=>'p', '&#80;'=>'p', '&#x70;'=>'p', '&#112;'=>'p', '&#x53;'=>'s', '&#83;'=>'s', '&#x73;'=>'s', '&#115;'=>'s', '&#x49;'=>'i', '&#73;'=>'i', '&#x69;'=>'i', '&#105;'=>'i', '&#x4f;'=>'o', '&#79;'=>'o', '&#x6f;'=>'o', '&#111;'=>'o', '&#x4e;'=>'n', '&#78;'=>'n', '&#x6e;'=>'n', '&#110;'=>'n', '&#x55;'=>'u', '&#85;'=>'u', '&#x75;'=>'u', '&#117;'=>'u', '&#x52;'=>'r', '&#82;'=>'r', '&#x72;'=>'r', '&#114;'=>'r', '&#x4c;'=>'l', '&#76;'=>'l', '&#x6c;'=>'l', '&#108;'=>'l', '&#x28;'=>'(', '&#40;'=>'(', '&#x29;'=>')', '&#41;'=>')', '&#x20;'=>':', '&#32;'=>':', '&#x22;'=>'"', '&#34;'=>'"', '&#x27;'=>"'", '&#39;'=>"'", '&#x2f;'=>'/', '&#47;'=>'/', '&#x2a;'=>'*', '&#42;'=>'*', '&#x5c;'=>'\\', '&#92;'=>'\\');
     $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('&#xad;', '&#173;', '&shy;'), ' ', $v) : $v)); # double-quoted char: soft-hyphen; appears here as "­" or hyphen or something else depending on viewing software

Replies

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin

    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

  • rdueckrdueck Posts: 12Questions: 2Answers: 0

    I set both to private initially, but got an error and switched it to public:

    PHP Fatal error:  Uncaught Error: Cannot access private property DataTables\\Database::$type in editor-php-2.0.10/lib/Database/Query.php:1185
    
  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin

    Agreed! Fix committed here.

    Allan

  • JxckSweeneyJxckSweeney Posts: 2Questions: 0Answers: 0

    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?

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin

    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

  • JxckSweeneyJxckSweeney Posts: 2Questions: 0Answers: 0

    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!

Sign In or Register to comment.