5to4.php 728 B

1234567891011121314151617
  1. <?php
  2. php5to4 ("../spyc.php", 'spyc-latest.php4');
  3. function php5to4 ($src, $dest) {
  4. $code = file_get_contents ($src);
  5. $code = preg_replace ('#(public|private|protected)\s+\$#i', 'var \$', $code);
  6. $code = preg_replace ('#(public|private|protected)\s+static\s+\$#i', 'var \$', $code);
  7. $code = preg_replace ('#(public|private|protected)\s+function#i', 'function', $code);
  8. $code = preg_replace ('#(public|private|protected)\s+static\s+function#i', 'function', $code);
  9. $code = preg_replace ('#throw new Exception\\(([^)]*)\\)#i', 'trigger_error($1,E_USER_ERROR)', $code);
  10. $code = str_replace ('self::', '$this->', $code);
  11. $f = fopen ($dest, 'w');
  12. fwrite($f, $code);
  13. fclose ($f);
  14. print "Written to $dest.\n";
  15. }