smarty icon indicating copy to clipboard operation
smarty copied to clipboard

PHP 8.2: Deprecation notices for dynamic properties

Open ophian opened this issue 2 years ago • 2 comments

Upcoming PHP 8.2 throws even more deprecation notices for removal approach in PHP 9.

[ I solved my questions by asking... ]

Solution proposal will follow.

ophian avatar Jun 29 '22 11:06 ophian

Improve for PHP 8.2 by using new AllowDynamicProperties flag only

------------ libs/sysplugins/smarty_internal_extension_handler.php ------------

@@ -36,6 +36,7 @@
  * @property   Smarty_Internal_Method_RegisterPlugin     $registerPlugin
  * @property   mixed|\Smarty_Template_Cached             configLoad
  */
+#[\AllowDynamicProperties]
 class Smarty_Internal_Extension_Handler
 {
     public $objType = null;

----------------- libs/sysplugins/smarty_internal_template.php ----------------

@@ -24,6 +24,7 @@
  *
  * @method bool mustCompile()
  */
+#[\AllowDynamicProperties]
 class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
 {
     /**

--------------------- libs/sysplugins/smarty_security.php ---------------------

@@ -19,6 +19,7 @@
 /**
  * This class does contain the security settings
  */
+#[\AllowDynamicProperties]
 class Smarty_Security
 {
     /**

--------------------- libs/sysplugins/smarty_variable.php ---------------------

@@ -7,6 +7,7 @@
  * @package    Smarty
  * @subpackage Template
  */
+#[\AllowDynamicProperties]
 class Smarty_Variable
 {
     /**

ophian avatar Jul 07 '22 10:07 ophian

PHP 8.2 sets HTML-ENTITIES deprecated and PHP 8.1 gave up ENT_COMPAT as default value for the triplet

Please double check if this is still operating as desired !!

Fix PHP 8.2 deprecation of flag HTML-ENTITIES ------------------- libs/plugins/modifiercompiler.escape.php -------------------

@@ -55,17 +55,17 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
             // no break
             case 'htmlall':
                 if (Smarty::$_MBSTRING) {
                     if ($_double_encode) {
                         // php >=5.2.3 - go native
-                        return 'mb_convert_encoding(htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' .
-                               var_export($char_set, true) . ', ' . var_export($double_encode, true) .
-                               '), "HTML-ENTITIES", ' . var_export($char_set, true) . ')';
+                        return 'htmlspecialchars_decode(mb_convert_encoding(htmlentities(' . $params[ 0 ] . ', ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, ' .
+                                var_export($char_set, true) . ', ' . var_export($double_encode, true) .
+                                '), ' . var_export($char_set, true) . '))';
                     } elseif ($double_encode) {
                         // php <5.2.3 - only handle double encoding
-                        return 'mb_convert_encoding(htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' .
-                               var_export($char_set, true) . '), "HTML-ENTITIES", ' . var_export($char_set, true) . ')';
+                        return 'htmlspecialchars_decode(mb_convert_encoding(htmlentities(' . $params[ 0 ] . ', ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, ' .
+                                var_export($char_set, true) . '), ' . var_export($char_set, true) . '))';
                     } else {
                         // fall back to modifier.escape.php
                     }
                 }
                 // no MBString fallback

ophian avatar Jul 07 '22 11:07 ophian

Fixed in #775

wisskid avatar Nov 23 '22 23:11 wisskid