-
-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make all functions static methods #53
Comments
Hey @BackEndTea , We actually spent quite some time wondering if I should go with the functions or the classes approach. Indeed, there is no functions autoloading in PHP, so all the files must be loaded upfront. What I really wanted to do with Safe was to write a library that was really easy to add and that did not disrupt your source code. You can simply add a single line ( But I was indeed a bit afraid of the performance issue. I don't no if you have seen it, but we recently made some performance benchmarks: https://github.com/thecodingmachine/safe/blob/master/performance/README.md Loading Safe functions takes ~700µs. I don't know your particular use case, but for all the applications I have been writing, this is really an overhead I can cope with. If you are looking for extreme performance, maybe you can have a look at other libraries that are doing similar things. For instance, nette/utils are wrapping most of the PHP functions in classes. They are throwing exceptions instead of returning false, but they also do much more (like reordering $needle and $haystack...) They do not cover as many functions as Safe do, but it's definitely a package worth checking! |
Thanks for the reply @moufmouf. I missed the benchmark, and I assumed the performance hit would be much more than just 700µs. A hit that small is something I should be able to cope with. |
I'd like to implement this library in one of my projects, but i'm a bit worried about the added overhead of all the files, when i won't use 90% of them.
So my proposal would be to change all the functions and add as static methods to classes.
So instead of calling
Safe\getcwd();
I would callSafe\Dir::getcwd();
. This means that the classes can be added to the autoloader through psr-4, and they won't be loaded unless needed.I understand that this would be a big BC break, but i think it has some benefits to take this approach.
The text was updated successfully, but these errors were encountered: