84 Chapter 2 Advanced Syntax Figure 2.13 Input
Polymorphism and Self-Modifying Code 85 Figure 2.14 Sample output of the function plotter. The function generated by parse_function() would be as follows for the example (m * x + b) / (x / 3) : function calculate($req_code, $x) { eval($req_code); return(($m * $x + $b) / ($x / 3)); } $req_code contains the input from the second form field, in this example $m = 10; $b = 20;. Executing that using eval() results in correct variable assignment for the next line, which already does all the calculation and that s it! Note: For important information about the eval() statement, see the earlier warning! The rest is straightforward function plotting; the for() loop iterates through a predefined range and uses calculate() to determine the curve sY value in each iteration.
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP Web Hosting services