Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Generated on May 16, 2024 via composer

thecodingmachine/safe v2.5.0

PHP core functions that throw exceptions instead of returning FALSE on error
Package summary
Share
0
issues
1
license
1
MIT
Package created
6 Sep 2018
Version published
5 Apr 2023
Maintainers
2
Total deps
1
Direct deps
0
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
thecodingmachine/safe@v2.5.0
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

0
All Dependencies CSV
β“˜ This is a list of thecodingmachine/safe 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities

Visualizations

Frequently Asked Questions

What does thecodingmachine/safe do?

Thecodingmachine/safe is a set of PHP core functions re-written to throw exceptions instead of returning false when an error is encountered. This offers a safer and more predictable handling of PHP functions.

How do you use thecodingmachine/safe?

To use thecodingmachine/safe, firstly, you would need to use composer for installation by running $ composer require thecodingmachine/safe. Then, in the PHP files, you need to import the "safe" variant of the functionality needed. For example, to use file_get_contents and json_decode functions, you would write:

use function Safe\file_get_contents;
use function Safe\json_decode;

$content = file_get_contents('foobar.json');
$foobar = json_decode($content);

It's highly recommended to also install PHPStan and PHPStan extension, which come with a rule to let you know each time you are using an "unsafe" PHP core function. To do this, run $ composer require --dev thecodingmachine/phpstan-safe-rule and add the required rules to your phpstan.neon file.

In addition, for larger projects, you can automate the refactoring using a tool called Rector. The specific guidance for the installation and usage of Rector with Safe is detailed in the readme.

Where are the thecodingmachine/safe docs?

Documentation for thecodingmachine/safe can be found in the readme document on its GitHub repository at https://github.com/thecodingmachine/safe. The readme provides detailed guidance on how to install, use, and contribute to Safe. Further instructions for performance testing and the list of core PHP functions that are re-written by Safe can also be found through the readme linked in the repository. To learn more about what triggered the development of Safe, you can read the release article on TheCodingMachine's blog linked in the readme as well.