Updating PHP Code to v.7

My mp3 player .php file worked fine years ago, but when I recently tried to use it again, it no longer works with PHP v.7.
I’ve run code through phptester.net and fixed first issue by changing $new to new, but now tester flags the following as unexpected (T_STRING) -

if ($this->mode & PEAR_ERROR_EXCEPTION) {
trigger_error(“PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions”, E_USER_WARNING);
eval(’$e = new Exception($this->message, $this->code);throw($e);’);
}
I’ve changed PEAR_ERROR_EXCEPTION to PEAR_Exception but phptester.net still flags the same line of code/
What must I change in code for it to be current and not obsolete?

The portion of using eval to me, means the code is just too bad to reconcile

There’s nothing that can replace eval?

Another error occurs at last line of this section of code -
$f_id=str_replace("/","",$file_title);
$f_id=str_replace(".","",$f_id);
$f_id=str_replace(">","",$f_id);
$f_id=str_replace("<","",$f_id);
$f_id=str_replace("=","",$f_id);
$f_id=str_replace("(","",$f_id);
$f_id=str_replace(")","",$f_id);
$f_id=str_replace(""","",$f_id);
PHPtester says unexpected ‘","’ expecting ‘,’ or ‘)’
so can “”","" be changed? to what?

First of all, the snippet of posted code, when put into a valid class context, doesn’t produce any syntax error in php7 (unless there’s something there that the forum software mangled.) The problem causing the syntax error is either due to the context where this code is at or is due to something at phptester. It would require having all the original code to even begin to be able to help. This is a PEAR extension. Which one? It may have been updated by the Author to work with php7?

Next, the syntax of $new was never valid for class creation. However, if the code was attempting to have a variable named $new with php version specific class creation syntax in it, this might explain the eval() usage (I would have used conditional logic, since there’s only two choices), but the string syntax would either have used double-quotes or concatenation. There’s nothing in the current posted code that requires the use of eval() and it should be eliminated, because if any of the values being put into the string could contain php/javascript, this code would allow either taking over your web site or doing cross site scripting.

If you literally changed PEAR_ERROR_EXCEPTION to PEAR_Exception in the posted code, that’s not what this code is trying to do and not what the user error message it produces means. It’s testing a bit in the mode property to see if an obsolete choice is being used. Once this code runs (it currently doesn’t due to the syntax error) and if it triggers the shown USER WARNING message, it means that the mode property needs to be changed. If on the other hand you did change the mode property, the current syntax error could be from some different code, rather than the posted code. Did you confirm that the file and line number in the latest error corresponds to the posted code?

Programming is context specific. Just making all errors go-away isn’t enough. You must consider what the context is, what the code is doing, when making changes.

Here’s .php file with unedited code - copy and paste at phptester.net to see errors I mention. I have no other way of determining why .php file no longer works. Not sure but code my be as old as 2008 or older. It worked around that time, but now won’t load mp3 tracks.
http://dstall.com/mp3player.php.zip

Just discovered the php file works fine and there’s nothing wrong with it.
The problem is with mp3 file.
See - dstall.com/mp3.zip
Track 01 displays and plays fine, but track 02 fails to display.
If I load track 02, it causes track 01 to disappear as well.
Any idea the difference between the tracks?
Is it because there’s no artist, album, etc. tags for track 02?

Added tags and now mp3 plays fine.

Sponsor our Newsletter | Privacy Policy | Terms of Service