First scan your directories and build a list of files. You have many examples of how to do this on [man]readdir[/man] manual page. Filter them to only show files with php extension.
Second, for each file in the list read file using [man]file_get_contents[/man] then add your line at the end and use [man]fopen[/man], [man]fwrite[/man], [man]fclose[/man] to save modified file.
You'd have to make all files writable by your server, so you should do it on the development server, rather then live one.