[man]eval/man can execute a PHP statement, even from a string.
You agree that if you had this, it would not be a problem:
$sum = 0+8+12;
Now your $total string is actually a part of that code: '0+8+12'
We can now add $sum = before and add one semicolon ; at the end.
Now we have the valid PHP statement: $sum = 0+8+12;
which can be evaluated with [man]eval/man
<?php
$string = "0+8+12";
$total = '$sum=' . $string . ';' ;
// $total is now "$sum=0+8+12;"
eval($total); // run the php statement
echo $sum; // displays 20 .. correct!
?>