View Issue Details

IDProjectCategoryView StatusLast Update
0030429mantisbtotherpublic2023-01-25 10:16
ReporterChrisG Assigned Todregad  
PriorityhighSeverityminorReproducibilityN/A
Status resolvedResolutionfixed 
Target Version2.25.6Fixed in Version2.25.6 
Summary0030429: Upcoming incompatibility with PHP 8.2, "Deprecate ${} string interpolation" RFC
Description

The "Deprecate ${} string interpolation" RFC (https://wiki.php.net/rfc/deprecate_dollar_brace_string_interpolation) has been passed. The Mantis code is using what is deprecated in a few places at the moment.
It should be simple to fix and it would be good to get done early.

Additional Information

I've attached the changes I think would be needed based on my copy of 2.24.0. I don't have the time to contribute a proper pull request at the moment I'm afraid.

TagsPHP 8.2
Attached Files
deprecate_dollar_brace_string_interpolation.diff (4,295 bytes)   
diff --git a/tracker/core/file_api.php b/core/file_api.php
index 06ebc5a1a4..2e663534d5 100644
--- a/core/file_api.php
+++ b/core/file_api.php
@@ -710,7 +710,7 @@ function diskfile_is_name_unique( $p_name, $p_filepath ) {
  * @return boolean true if unique
  */
 function file_is_name_unique( $p_name, $p_bug_id, $p_table = 'bug' ) {
-       $t_file_table = db_get_table( "${p_table}_file" );
+       $t_file_table = db_get_table( "{$p_table}_file" );
 
        db_param_push();
        $t_query = 'SELECT COUNT(*) FROM ' . $t_file_table . ' WHERE filename=' . db_param();
diff --git a/core/plugin_api.php b/core/plugin_api.php
index eda53f62ff..8b85e134c7 100644
--- a/core/plugin_api.php
+++ b/core/plugin_api.php
@@ -420,7 +420,7 @@ function plugin_error( $p_error_name, $p_error_type = ERROR, $p_basename = null
                $t_basename = $p_basename;
        }
 
-       $t_error_code = "plugin_${t_basename}_${p_error_name}";
+       $t_error_code = "plugin_{$t_basename}_{$p_error_name}";
 
        trigger_error( $t_error_code, $p_error_type );
 }
@@ -1030,7 +1030,7 @@ function plugin_init( $p_basename ) {
                $t_plugin_errors = $t_plugin->errors();
 
                foreach( $t_plugin_errors as $t_error_name => $t_error_string ) {
-                       $t_error_code = "plugin_${p_basename}_${t_error_name}";
+                       $t_error_code = "plugin_{$p_basename}_{$t_error_name}";
                        $g_lang_strings[$t_lang]['MANTIS_ERROR'][$t_error_code] = $t_error_string;
                }
 
diff --git a/core/string_api.php b/core/string_api.php
index e14a652d4c..f0da6db6c8 100644
--- a/core/string_api.php
+++ b/core/string_api.php
@@ -492,15 +492,15 @@ function string_insert_hrefs( $p_string ) {
 
                # valid set of characters that may occur in url scheme. Note: - should be first (A-F != -AF).
                $t_url_valid_chars       = '-_.,!~*\';\/?%^\\\\:@&={\|}+$#[:alnum:]\pL';
-               $t_url_chars             = "(?:${t_url_hex}|[${t_url_valid_chars}\(\)\[\]])";
-               $t_url_chars2            = "(?:${t_url_hex}|[${t_url_valid_chars}])";
-               $t_url_chars_in_brackets = "(?:${t_url_hex}|[${t_url_valid_chars}\(\)])";
-               $t_url_chars_in_parens   = "(?:${t_url_hex}|[${t_url_valid_chars}\[\]])";
+               $t_url_chars             = "(?:{$t_url_hex}|[{$t_url_valid_chars}\(\)\[\]])";
+               $t_url_chars2            = "(?:{$t_url_hex}|[{$t_url_valid_chars}])";
+               $t_url_chars_in_brackets = "(?:{$t_url_hex}|[{$t_url_valid_chars}\(\)])";
+               $t_url_chars_in_parens   = "(?:{$t_url_hex}|[{$t_url_valid_chars}\[\]])";
 
                $t_url_part1 = $t_url_chars;
-               $t_url_part2 = "(?:\(${t_url_chars_in_parens}*\)|\[${t_url_chars_in_brackets}*\]|${t_url_chars2})";
+               $t_url_part2 = "(?:\({$t_url_chars_in_parens}*\)|\[{$t_url_chars_in_brackets}*\]|{$t_url_chars2})";
 
-               $s_url_regex = "/(${t_url_protocol}(${t_url_part1}*?${t_url_part2}+))/su";
+               $s_url_regex = "/({$t_url_protocol}({$t_url_part1}*?{$t_url_part2}+))/su";
 
                # e-mail regex
                $s_email_regex = substr_replace( email_regex_simple(), '(?:mailto:)?', 1, 0 );
@@ -516,7 +516,7 @@ function string_insert_hrefs( $p_string ) {
                        } else {
                                $t_url_target = '';
                        }
-                       return "<a ${t_url_href}${t_url_target}>${p_match[1]}</a>";
+                       return "<a {$t_url_href}{$t_url_target}>{$p_match[1]}</a>";
                },
                $p_string
        );
diff --git a/login_page.php b/login_page.php
index 69830ba051..a08f7619a8 100644
--- a/login_page.php
+++ b/login_page.php
@@ -165,7 +165,7 @@ if( config_get_global( 'admin_checks' ) == ON ) {
        function debug_setting_message ( $p_type, $p_setting, $p_value ) {
                return sprintf( lang_get( 'warning_change_setting' ), $p_setting, $p_value )
                        . sprintf( lang_get( 'word_separator' ) )
-                       . sprintf( lang_get( "warning_${p_type}_hazard" ) );
+                       . sprintf( lang_get( "warning_{$p_type}_hazard" ) );
        }
 
        $t_config = 'show_detailed_errors';

Relationships

has duplicate 0031934 resolveddregad Deprecated 

Activities

atrol

atrol

2022-06-01 03:40

developer   ~0066662

Last edited: 2022-06-01 03:41

I've attached the changes I think would be needed based on my copy of 2.24.0

@ChrisG as a side note, I expect you will encounter some more issues when using PHP 8.2 to run MantisBT 2.24.0.
At the moment there are 13 issues that have been fixed after 2.24.0 to support PHP 8.0 and 8.1.

ChrisG

ChrisG

2022-06-01 12:41

reporter   ~0066663

Thanks. I have a fork of Mantis in a big monolithic repository I maintain, and regularly scan the whole repository for forthcoming compat issues where possible. So this is more me sharing my findings, not me wanting to actually stick to that particular older version.

dregad

dregad

2022-06-02 05:37

developer   ~0066665

Thanks for the patch @ChrisG, I actually had this on my to-do list.

As a side note, it would have been even nicer if you had not switched indents from tabs to spaces, as I could not apply it automatically. Since it was only minor changes to a just a few lines, it's no big deal, but if you could please keep that in mind for future contributions it would be great.

PR https://github.com/mantisbt/mantisbt/pull/1820

obmsch

obmsch

2022-06-02 17:55

reporter   ~0066681

@dregad a grep on my sources shows some more of the ${ pattern.

1) ${'f_' . $t_key} 4 times in "admin/install.php"
Amend PR
2) $s_permalink .= &quot;&${p_string}[]=$t_value&quot;; in "plugins/Source/Source.FilterAPI.php"
Fix upstream
3) ${$... 3 times in "vendor/adodb/adodb-php/drivers/adodb-db2.inc.php"
Fix upstream
I personally don't care that much of a php version a couple of months away, but if we want
to address this rfc right now, (1) should be in the PR as well.

ChrisG

ChrisG

2022-06-02 22:56

reporter   ~0066682

@dregad I think that whitespace borking came from me copy & pasting from a "git diff" on the terminal. Will bear in mind in the future. Ideally I'd put through a proper pull request, just I've got a baby at the moment sucking on a lot of things including my time.

dregad

dregad

2022-06-03 02:37

developer   ~0066683

@obmsch thanks for the feedback

1) ${'f_' . $t_key} 4 times in "admin/install.php"

I did notice these, but they do not need to be touched because it's the Variable variables outside of strings case, which is unchanged by the RFC

2) $s_permalink .= "${p_string}[]=$t_value"; in "plugins/Source/Source.FilterAPI.php"
3) ${$... 3 times in "vendor/adodb/adodb-php/drivers/adodb-db2.inc.php"

Thanks for the heads up on these, I'll take care of them. Anyway as you said there is no rush, since PHP 8.2 is only due in November.

@ChrisG

No worries, and congratulations :-)

I can live without a PR, but what you could easily do with very little overhead is, instead of copy/paste: git diff >patch.diff and attach that file

dregad

dregad

2022-06-03 03:10

developer   ~0066684

2) $s_permalink .= "${p_string}[]=$t_value"; in "plugins/Source/Source.FilterAPI.php"

Source integration plugin fixed: https://github.com/mantisbt-plugins/source-integration/issues/396

dregad

dregad

2022-06-03 11:33

developer   ~0066686

3) ${$... 3 times in "vendor/adodb/adodb-php/drivers/adodb-db2.inc.php"

The 3 occurrences are also of the Variable variables outside of strings sort, so no changes are needed on the ADOdb side.

dregad

dregad

2022-09-03 05:40

developer   ~0066964

Changing target to 2.25.6, as I've hit a conflict resolution when merging another issue and we might as well have PHP 8.2 compatibility in 2.25 branch.

Related Changesets

MantisBT: master c3cbfe2c

2022-06-02 05:31

dregad


Details Diff
Fix deprecated usage of ${} string interpolation

The "Deprecate ${} string interpolation" RFC [1] has been acceoted and
will be implemented in PHP 8.2.

The Mantis code was using the deprecated syntax in a few places, this
fixes these occurrences.

Thanks to ChrisG for the original patch.

Fixes 0030429

[1]: https://wiki.php.net/rfc/deprecate_dollar_brace_string_interpolation
Affected Issues
0030429
mod - core/file_api.php Diff File
mod - core/plugin_api.php Diff File
mod - core/string_api.php Diff File
mod - login_page.php Diff File

MantisBT: master-2.25 3b2ec19e

2022-06-02 05:31

dregad


Details Diff
Fix deprecated usage of ${} string interpolation

The "Deprecate ${} string interpolation" RFC [1] has been acceoted and
will be implemented in PHP 8.2.

The Mantis code was using the deprecated syntax in a few places, this
fixes these occurrences.

Thanks to ChrisG for the original patch.

Fixes 0030429

[1]: https://wiki.php.net/rfc/deprecate_dollar_brace_string_interpolation

(cherry picked from commit c3cbfe2c90240d15bf0e450254cbeb68050655ba)

# Conflicts:
# core/string_api.php
Affected Issues
0030429
mod - core/file_api.php Diff File
mod - core/plugin_api.php Diff File
mod - core/string_api.php Diff File
mod - login_page.php Diff File