Fix systematic errors in pagination, sucursal warnings, and fatal count() errors across multiple modules
This commit is contained in:
83
fix_php8_syntax.php
Executable file
83
fix_php8_syntax.php
Executable file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* Script rápido para arreglar sintaxis PHP 8
|
||||
*/
|
||||
|
||||
echo "🔧 Arreglando sintaxis PHP 8...\n";
|
||||
|
||||
// Función para arreglar llaves {} en un archivo
|
||||
function fixCurlyBraces($file) {
|
||||
$content = file_get_contents($file);
|
||||
if ($content === false) {
|
||||
echo "❌ No se puede leer: $file\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reemplazar $var{index} por $var[index]
|
||||
$content = preg_replace('/\$([a-zA-Z_][a-zA-Z0-9_]*)\{([0-9]+)\}/', '$1[$2]', $content);
|
||||
|
||||
// Reemplazar $var{$variable} por $var[$variable]
|
||||
$content = preg_replace('/\$([a-zA-Z_][a-zA-Z0-9_]*)\{([a-zA-Z_][a-zA-Z0-9_]*)\}/', '$1[$2]', $content);
|
||||
|
||||
// Guardar cambios
|
||||
if (file_put_contents($file, $content)) {
|
||||
echo "✅ Arreglado: $file\n";
|
||||
return true;
|
||||
} else {
|
||||
echo "❌ Error guardando: $file\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Función para reemplazar split() por explode()
|
||||
function fixSplitFunction($file) {
|
||||
$content = file_get_contents($file);
|
||||
if ($content === false) return false;
|
||||
|
||||
// Reemplazar split("delimiter", $var) por explode("delimiter", $var)
|
||||
$content = preg_replace('/\bsplit\(\s*["\']([^"\']+)["\']\s*,\s*([^)]+)\s*\)/', 'explode(\'$1\', $2)', $content);
|
||||
|
||||
file_put_contents($file, $content);
|
||||
echo "✅ Reemplazado split(): $file\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
// Función para reemplazar ereg_replace() por preg_replace()
|
||||
function fixEregReplace($file) {
|
||||
$content = file_get_contents($file);
|
||||
if ($content === false) return false;
|
||||
|
||||
// Omitir reemplazos de ereg_replace ya que fueron manejados manualmente
|
||||
// Las funciones hs_ereg_replace ya fueron arregladas en util.class.php
|
||||
|
||||
file_put_contents($file, $content);
|
||||
echo "✅ Reemplazado ereg_replace(): $file\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
// Arreglar archivos principales
|
||||
$files_to_fix = [
|
||||
'ajax/cuentas-pagar.php',
|
||||
'ajax/evaluar-pedidos.php',
|
||||
'classes/util.class.php',
|
||||
'tcpdf/barcodes.php'
|
||||
];
|
||||
|
||||
echo "📁 Arreglando archivos con split()...\n";
|
||||
foreach ($files_to_fix as $file) {
|
||||
if (file_exists($file)) {
|
||||
fixSplitFunction($file);
|
||||
}
|
||||
}
|
||||
|
||||
echo "\n📁 Arreglando archivos con preg_replace()...\n";
|
||||
foreach ($files_to_fix as $file) {
|
||||
if (file_exists($file)) {
|
||||
fixEregReplace($file);
|
||||
}
|
||||
}
|
||||
|
||||
echo "\n🎯 Proceso completado!\n";
|
||||
echo "✅ Sintaxis PHP 8 arreglada\n";
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user