Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate curly brace syntax for accessing array elements and string offsets #5727

Open
jdarwood007 opened this issue Jul 4, 2019 · 2 comments

Comments

Projects
None yet
4 participants
@jdarwood007
Copy link
Member

commented Jul 4, 2019

Description

Seems that the PHP development team is deprecating using $var{#INDEX#} syntax.
I did a quick search of the code base and found a few occurrences. Due to this being deprecated, we should take care to resolve these before final.

Zeus:SMF2.1 jeremy$ egrep -R '$[A-Za-z0-9]*{' .
./Sources/Subs-Package.php: while ($flags & 8 && $data{$offset++} != "\0")
./Sources/Subs-Package.php: while ($flags & 4 && $data{$offset++} != "\0")
./Sources/Subs-Package.php: $checksum += ord($header{$i});
./Sources/Subs-Package.php: $checksum += ord($header{$i});
./Sources/Subs-Package.php: $pass{$i} = chr(ord($pass{$i}) ^ (ord($salt{$i}) - 32));
./Sources/Register.php: if ($_REQUEST['letter'] > 0 && $_REQUEST['letter'] <= strlen($code) && !showLetterImage(strtolower($code{$REQUEST['letter'] - 1})))
./Sources/ManageLanguages.php: if ($string{$i} == '\')
./Sources/ManageLanguages.php: elseif (($string{$i} == 'n' || $string{$i} == 't') && $in_string == 2 && $is_escape)
./Sources/ManageLanguages.php: $new_string .= $string{$i} == 'n' ? "\n" : "\t";
./Sources/ManageLanguages.php: elseif ($string{$i} == ''')
./Sources/ManageLanguages.php: elseif ($string{$i} == '"')
./Sources/ManageLanguages.php: elseif ($in_string == 0 && (empty($string{$i}) || $string{$i} == '.'))
./Sources/ManageLanguages.php: elseif ($in_string == 0 && $string{$i} == '$')
./Sources/ManageLanguages.php: $new_string .= $string{$i};
./Sources/ManageLanguages.php: if ($string{$i} == '{' && $string{$i + 1} == '%' && $string{$i + 2} == '$')
./Sources/ManageLanguages.php: elseif ($string{$i} == '<')
./Sources/ManageLanguages.php: if ($string{$i + 1} != ' ')
./Sources/ManageLanguages.php: elseif ($string{$i} == '>')
./Sources/ManageLanguages.php: if ($string{$i} == '\')
./Sources/ManageLanguages.php: elseif ($string{$i} == '"')
./Sources/ManageLanguages.php: elseif ($string{$i} == ''')
./Sources/ManageLanguages.php: $new_string .= $string{$i};
./Sources/Subs.php: $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
./Sources/Packages.php: ${"package
$key"} = un_htmlspecialchars($packageInfo[$key]);
./Sources/Class-Graphics.php: $this->Buf[2 + $i] = ord($data{$i});
./Sources/Class-Graphics.php: $bmp .= $data{$i};
./Sources/Subs-Graphics.php: $b = ord($palettedata{$j++});
./Sources/Subs-Graphics.php: $g = ord($palettedata{$j++});
./Sources/Subs-Graphics.php: $r = ord($palettedata{$j++});
./Sources/Subs-Graphics.php: 'id' => $code{$i},
./Sources/Subs-Sound.php: $sound_letter = implode('', file($settings['default_theme_dir'] . '/fonts/sound/' . $word{$i} . '.' . $sound_language . '.wav'));
./Sources/Subs-Sound.php: switch ($word{$i} === 's' ? 0 : mt_rand(0, 2))
./Sources/Subs-Sound.php: $sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(mt_rand(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF)));
./Sources/Subs-Compat.php: $blks[$i >> 2] |= ord($str{$i}) << (24 - ($i % 4) * 8);

Additional information/references

https://wiki.php.net/rfc/deprecate_curly_braces_array_access
php/php-src@PHP-7.4...rjhdby:deprecate_alternate_array_access

@VBGAMER45

This comment has been minimized.

Copy link
Contributor

commented Jul 5, 2019

Wow never realized that was a thing.

@jdarwood007

This comment has been minimized.

Copy link
Member Author

commented Jul 5, 2019

yep, typically used when you want to read a single character out of a string.

PHP internals seems to be discussing maybe other methods. Even though this went to vote. https://news-web.php.net/php.internals/106147

@MissAllSunday MissAllSunday added this to the Final milestone Jul 18, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.