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