Type in a math expression (e.g. sin(x)*x) - the server samples the curve in PHP with its OWN, hand-written expression parser (tokenizer → syntax tree → safe, whitelisted evaluation). No eval(): the input never becomes executed code, it can only ever be a parameter to a strictly whitelisted set of math functions.
// Fehérlistás dispatch - KIZÁRÓLAG ez a néhány függvény hívható,
// SOSEM dinamikus "$name(...)" hívás vagy eval()
public static function callOne(string $name, float $x): float
{
return match ($name) {
'sin' => sin($x),
'sqrt' => sqrt($x),
'ln' => log($x),
// ...
};
}
// Osztás/maradék fdiv()/fmod()-mal (nullával osztás -> csendes INF/NAN,
// SOSEM DivisionByZeroError), majd EGYSÉGES NaN/Inf-kapu:
'/' => fdiv($left, $right),
...
if (is_nan($result) || is_infinite($result)) {
return null; // szakadt pont a grafikonon, nem hiba
}The free variable is called 'x'. Available constants: pi, e. Functions: sin, cos, tan, sqrt, abs, exp, ln, log10, log2, floor, ceil, round, sign, pow(x,n), log(x,base), min(a,b), max(a,b).
Roots (approximate x values): -9.4248, -6.2832, -3.1416, 0, 3.1416, 6.2832, 9.4248