In PHP 7.4 wirft etwas wie das hier die Fehlermeldung "Deprecated: Array and string offset access syntax with curly braces is deprecated in php"
<?php
$bar="Hallo";
$i=3;
$tok=1;
$foo = $bar{1};
$foo = $bar{ 1 };
$foo = $bar{ 1+3 };
$foo = $bar{ $tok + 3 }; $foo = $bar{$i};
Das will man natürlich ggf. nicht von Hand umschreiben, ein Ein- bis Dreizeiler (Wofür, bittschön, habe ich denn sonst Linux?) muss also her. Ein Test mit
/tmp> sed --in-place="-`date +%Y%m%d_%I%M`" -E -e 's/\$([a-zA-Z0-9_]+)\{([^\}]*)\}/\$\1[\2]/g' test.php
führt scheinbar erfolgreich zum richtigen Ergebnis:
<?php
$bar="Hallo";
$i=3;
$tok=1;
$foo = $bar[1];
$foo = $bar[ 1 ];
$foo = $bar[ 1+3 ];
$foo = $bar[ $tok + 3 ]; $foo = $bar[$i];
Frage: Bevor ich das jetzt mit
find --name '*.php' -exec sed --in-place="-`date +%Y%m%d_%I%M`" -E -e 's/\$([a-zA-Z0-9_]+)\{([^\}]*)\}/\$\1[\2]/g' {} \;;
würde ich nur zu gern wissen, welche Schäden andere an meinen Skripten erwarten würden.