Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Math Eval Laravel Package

langleyfoxall/math_eval

Safely evaluate math expressions in PHP. langleyfoxall/math_eval parses and computes strings with operators, brackets, and common functions, ideal for user-defined formulas and configuration values without using eval(). Lightweight and easy to integrate in Laravel or any PHP app.

View on GitHub
Deep Wiki
Context7

✖️➕➖➗ math_eval safely evaluates mathematical expressions

Frequently asked questions about Math Eval
How do I install `langleyfoxall/math_eval` in a Laravel project?
Run `composer require langleyfoxall/math_eval` in your project root. No additional Laravel-specific setup is required, though you may want to wrap the function in a service class for better organization. The package works with Laravel 5.5+ and PHP 7.1+.
Can I use this package to evaluate user-submitted math expressions safely?
Yes, the package avoids `eval()` and uses a sandboxed parser, but you should still validate input to restrict allowed functions/operators. Whitelist expressions or use Laravel’s `Validator` to sanitize before evaluation. Avoid recursive functions or overly complex expressions to prevent memory exhaustion.
Does `math_eval` support advanced functions like `sin()`, `log()`, or custom variables?
It supports basic math functions (e.g., `sqrt()`, `pow()`) and variables passed as an associative array. For advanced functions, check the [README](https://github.com/langleyfoxall/math_eval) for supported operations. If you need more, consider alternatives like `league/math` or `symfony/math`.
Is this package compatible with Laravel 9/10 and PHP 8.x?
The package officially supports PHP 7.1+, but the latest release (v2.1.0) only updates dev dependencies. Test thoroughly on PHP 8.1+ to confirm compatibility, especially if using newer Laravel features. No native Laravel 9/10 integrations exist, so manual setup is required.
How do I handle errors if a math expression is invalid or malformed?
The package throws exceptions for invalid syntax or unsupported operations. Wrap calls in a `try-catch` block to handle errors gracefully. Log failed expressions for debugging, and consider adding custom validation rules in Laravel’s `Validator` to reject unsafe input before evaluation.
What are the performance implications of using `math_eval` for high-volume calculations?
This is a pure PHP implementation, so performance may lag for heavy workloads. Benchmark against alternatives like `php-math` or `symfony/math` if throughput is critical. Cache frequent expressions or precompute results where possible to mitigate overhead.
Are there any security risks I should be aware of when using user input?
While the package avoids `eval()`, edge cases like deeply nested expressions or malicious input could still cause issues (e.g., memory exhaustion). Restrict allowed functions/variables, set `ini_set('max_execution_time', 1)` for safety, and avoid enabling unsupported operations. Always validate input before evaluation.
How does `math_eval` compare to alternatives like `symfony/math` or `league/math`?
`math_eval` is lightweight and simple, ideal for basic arithmetic and user-defined formulas. Alternatives like `symfony/math` or `league/math` offer more features (e.g., matrix operations, PHP 8.x optimizations) and active maintenance. Choose based on your needs: simplicity vs. extensibility.
Can I integrate `math_eval` into Laravel’s service container or facades?
Yes, manually bind the `math_eval` function to Laravel’s service container using `app()->bind()` or create a facade for cleaner syntax. Example: `Facade::eval('2 + 2')`. This improves reusability and testing, especially in larger applications.
Is the package actively maintained? Should I fork it for long-term use?
The last functional release was in 2019, with v2.1.0 (2023) only updating dev dependencies. No core maintenance activity exists, so fork immediately if you need security fixes or PHP 8.x+ support. Monitor for compatibility issues, especially with newer Laravel versions.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor