Safe
[DISCONTINUED] 🛡 PHP functions smarten up to throw exceptions instead of returning false or triggering errors.
Install / Use
/learn @nette-discontinued/SafeREADME
Nette Safe [DISCONTINUED]
PHP functions smarten up to throw exceptions instead of returning false or triggering errors.
Good programmers do not ignore the errors
At least they shouldn't. PHP is a language with a relatively lax approach to errors, and therefore it requires the programmer to make more effort in handling them. Almost all PHP functions report errors using a return value, and the programmer must constantly check them for error states. There is a risk of forgetting it. Example:
// we are making copy of file
copy('/oldfile', '/newfile');
unlink('/oldfile');
If the first line fails, the file is permanently deleted. It would be much more useful if PHP throws an exception.
The problem of return values is also that it is not clear exactly what error occurred. Conversely eceptions have a text message and optionally an error code.
The solution is Nette\Safe
The use is extremely simple. Before each PHP function that should throws an exception instead of a warning, simply type Safe:
use Nette\Safe;
// we are making copy of file
Safe::copy('/oldfile', '/newfile');
Safe::unlink('/oldfile');
If the first line fails, exception Nette\Safe\FilesystemException is thrown and the file is not deleted.
Installation
composer require nette/safe
It requires PHP version 7.1 and supports PHP up to 7.4.
Exceptions
Nette\Safe throws exception Nette\Safe\Exception. For finer resolution you can catch its descendants, click to see:
| function | exception
| ------------- |-------------
| apache_get_version | Nette\Safe\ApacheException
| apache_getenv | Nette\Safe\ApacheException
| apache_request_headers | Nette\Safe\ApacheException
| apache_reset_timeout | Nette\Safe\ApacheException
| apache_response_headers | Nette\Safe\ApacheException
| apache_setenv | Nette\Safe\ApacheException
| apc_bin_loadfile | Nette\Safe\ApcException
| apc_cache_info | Nette\Safe\ApcException
| apc_cas | Nette\Safe\ApcException
| apc_compile_file | Nette\Safe\ApcException
| apc_dec | Nette\Safe\ApcException
| apc_define_constants | Nette\Safe\ApcException
| apc_delete | Nette\Safe\ApcException
| apc_delete_file | Nette\Safe\ApcException
| apc_inc | Nette\Safe\ApcException
| apc_load_constants | Nette\Safe\ApcException
| apc_sma_info | Nette\Safe\ApcException
| apcu_cache_info | Nette\Safe\ApcuException
| apcu_cas | Nette\Safe\ApcuException
| apcu_dec | Nette\Safe\ApcuException
| apcu_inc | Nette\Safe\ApcuException
| apcu_sma_info | Nette\Safe\ApcuException
| array_combine | Nette\Safe\ArrayException
| array_flip | Nette\Safe\ArrayException
| array_multisort | Nette\Safe\ArrayException
| array_replace | Nette\Safe\ArrayException
| array_replace_recursive | Nette\Safe\ArrayException
| array_walk_recursive | Nette\Safe\ArrayException
| arsort | Nette\Safe\ArrayException
| asort | Nette\Safe\ArrayException
| assert_options | Nette\Safe\InfoException
| base64_decode | Nette\Safe\UrlException
| bzclose | Nette\Safe\Bzip2Exception
| bzflush | Nette\Safe\Bzip2Exception
| bzread | Nette\Safe\Bzip2Exception
| bzwrite | Nette\Safe\Bzip2Exception
| chdir | Nette\Safe\DirException
| chgrp | Nette\Safe\FilesystemException
| chmod | Nette\Safe\FilesystemException
| chown | Nette\Safe\FilesystemException
| chroot | Nette\Safe\DirException
| class_alias | Nette\Safe\ClassobjException
| class_implements | Nette\Safe\SplException
| class_parents | Nette\Safe\SplException
| class_uses | Nette\Safe\SplException
| cli_set_process_title | Nette\Safe\InfoException
| closelog | Nette\Safe\NetworkException
| com_event_sink | Nette\Safe\ComException
| com_load_typelib | Nette\Safe\ComException
| com_print_typeinfo | Nette\Safe\ComException
| convert_uudecode | Nette\Safe\StringsException
| convert_uuencode | Nette\Safe\StringsException
| copy | Nette\Safe\FilesystemException
| create_function | Nette\Safe\FunchandException
| cubrid_free_result | Nette\Safe\CubridException
| cubrid_get_charset | Nette\Safe\CubridException
| cubrid_get_client_info | Nette\Safe\CubridException
| cubrid_get_db_parameter | Nette\Safe\CubridException
| cubrid_get_server_info | Nette\Safe\CubridException
| cubrid_insert_id | Nette\Safe\CubridException
| cubrid_lob2_new | Nette\Safe\CubridException
| cubrid_lob2_size | Nette\Safe\CubridException
| cubrid_lob2_size64 | Nette\Safe\CubridException
| cubrid_lob2_tell | Nette\Safe\CubridException
| cubrid_lob2_tell64 | Nette\Safe\CubridException
| cubrid_set_db_parameter | Nette\Safe\CubridException
| curl_escape | Nette\Safe\CurlException
| curl_exec | Nette\Safe\CurlException
| curl_getinfo | Nette\Safe\CurlException
| curl_init | Nette\Safe\CurlException
| curl_multi_errno | Nette\Safe\CurlException
| curl_multi_info_read | Nette\Safe\CurlException
| curl_multi_init | Nette\Safe\CurlException
| curl_setopt | Nette\Safe\CurlException
| curl_setopt_array | Nette\Safe\CurlException
| curl_share_errno | Nette\Safe\CurlException
| curl_share_setopt | Nette\Safe\CurlException
| curl_unescape | Nette\Safe\CurlException
| date_parse | Nette\Safe\DatetimeException
| date_parse_from_format | Nette\Safe\DatetimeException
| date_sun_info | Nette\Safe\DatetimeException
| date_sunrise | Nette\Safe\DatetimeException
| date_sunset | Nette\Safe\DatetimeException
| db2_autocommit | Nette\Safe\IbmDb2Exception
| db2_bind_param | Nette\Safe\IbmDb2Exception
| db2_client_info | Nette\Safe\IbmDb2Exception
| db2_close | Nette\Safe\IbmDb2Exception
| db2_commit | Nette\Safe\IbmDb2Exception
| db2_execute | Nette\Safe\IbmDb2Exception
| db2_free_result | Nette\Safe\IbmDb2Exception
| db2_free_stmt | Nette\Safe\IbmDb2Exception
| db2_get_option | Nette\Safe\IbmDb2Exception
| db2_pclose | Nette\Safe\IbmDb2Exception
| db2_rollback | Nette\Safe\IbmDb2Exception
| db2_server_info | Nette\Safe\IbmDb2Exception
| db2_set_option | Nette\Safe\IbmDb2Exception
| define | Nette\Safe\MiscException
| deflate_add | Nette\Safe\ZlibException
| deflate_init | Nette\Safe\ZlibException
| disk_free_space | Nette\Safe\FilesystemException
| disk_total_space | Nette\Safe\FilesystemException
| dl | Nette\Safe\InfoException
| dns_get_record | Nette\Safe\NetworkException
| eio_busy | Nette\Safe\EioException
| eio_chmod | Nette\Safe\EioException
| eio_chown | Nette\Safe\EioException
| eio_close | Nette\Safe\EioException
| eio_custom | Nette\Safe\EioException
| eio_dup2 | Nette\Safe\EioException
| eio_event_loop | Nette\Safe\EioException
| eio_fallocate | Nette\Safe\EioException
| eio_fchmod | Nette\Safe\EioException
| eio_fdatasync | Nette\Safe\EioException
| eio_fstat | Nette\Safe\EioException
| eio_fstatvfs | Nette\Safe\EioException
| eio_fsync | Nette\Safe\EioException
| eio_ftruncate | Nette\Safe\EioException
| eio_futime | Nette\Safe\EioException
| eio_grp | Nette\Safe\EioException
| eio_lstat | Nette\Safe\EioException
| eio_mkdir | Nette\Safe\EioException
| eio_mknod | Nette\Safe\EioException
| eio_nop | Nette\Safe\EioException
| eio_readahead | Nette\Safe\EioException
| eio_readdir | Nette\Safe\EioException
| eio_readlink | Nette\Safe\EioException
| eio_rename | Nette\Safe\EioException
| eio_rmdir | Nette\Safe\EioException
| eio_seek | Nette\Safe\EioException
| eio_sendfile | Nette\Safe\EioException
| eio_stat | Nette\Safe\EioException
| eio_statvfs | Nette\Safe\EioException
| eio_symlink | Nette\Safe\EioException
| eio_sync | Nette\Safe\EioException
| eio_sync_file_range | Nette\Safe\EioException
| eio_syncfs | Nette\Safe\EioException
| eio_truncate | Nette\Safe\EioException
| eio_unlink | Nette\Safe\EioException
| eio_utime | Nette\Safe\EioException
| eio_write | Nette\Safe\EioException
| error_log | Nette\Safe\ErrorfuncException
| event_add | Nette\Safe\LibeventException
| event_base_loopbreak | Nette\Safe\LibeventException
| event_base_loopexit | Nette\Safe\LibeventException
| event_base_new | Nette\Safe\LibeventException
| event_base_priority_init | Nette\Safe\LibeventException
| event_base_reinit | Nette\Safe\LibeventException
| event_base_set | Nette\Safe\LibeventException
| event_buffer_base_set | Nette\Safe\LibeventException
| event_buffer_disable | Nette\Safe\LibeventException
| event_buffer_enable | Nette\Safe\LibeventException
| event_buffer_new | Nette\Safe\LibeventException
| event_buffer_priority_set | Nette\Safe\LibeventException
| event_buffer_set_callback | Nette\Safe\LibeventException
| event_buffer_write | Nette\Safe\LibeventException
| event_del | Nette\Safe\LibeventException
| event_new | Nette\Safe\LibeventException
| `event_priority_s
Related Skills
node-connect
342.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
342.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.7kCommit, push, and open a PR
