mossadal/math-parser
Safe PHP math expression parser/evaluator that builds an AST from user formulas. Supports arithmetic, variables, and elementary functions, plus interpreters for evaluation, symbolic differentiation, and LaTeX pretty-printing; customizable lexer/parser with StdMathParser.
eval() usage with a controlled, AST-based evaluation system, reducing security risks associated with user-submitted code.Adopt if:
eval() while parsing untrusted input.Look elsewhere if:
For Executives:
"This package allows us to embed dynamic mathematical formulas into our product—such as custom pricing rules, scientific simulations, or rule-based workflows—without building a parser from scratch. It’s secure (no eval), supports advanced features like symbolic differentiation for algorithmic use cases, and even generates LaTeX for better user experience in documentation or dashboards. By adopting this solution, we can accelerate feature development, reduce technical debt, and enhance our product’s capabilities in math-heavy domains with minimal risk."
For Engineers:
"The mossadal/math-parser package provides a robust, PHP-based solution for parsing and evaluating mathematical expressions, including support for variables, elementary functions, implicit multiplication, and symbolic differentiation. It integrates seamlessly with Laravel via Composer and offers three interpreters: an evaluator for numeric results, a differentiator for symbolic math, and a LaTeX generator for rich output. The package is lightweight, well-documented, and avoids the security pitfalls of eval(). While it may not handle the most complex numerical computing tasks, it’s a solid choice for dynamic formula evaluation, optimization algorithms, or educational tools. The LGPL-3.0 license is permissive for most use cases, though we should ensure compliance if we modify the code."
For Product Managers: "This package enables us to deliver features like customizable calculators, dynamic pricing models, or scientific simulations without heavy engineering lift. For example, we could add a ‘custom formula’ field to our pricing tool, allowing users to define their own cost structures using mathematical expressions. The symbolic differentiation feature could also unlock advanced use cases like optimization algorithms or AI training data generation. By leveraging this solution, we can iterate faster on math-related features while maintaining security and scalability."
How can I help you explore Laravel packages today?