4 ms·
I see couple singletons calls in those examples. Is it considered a good practice in PHP now, or was it made to simplify the demoed code?
by SergeAx 3y ago
I see couple singletons calls in those examples. Is it considered a good practice in PHP now, or was it made to simplify the demoed code?
- simonhamp 3y agoMaybe you mean 'static' calls? Depends on the context but in most cases these are a convenience, syntactic sugar. Take SendOrderToVendor::dispatch($order)->onQueue('orders'), for example. This could also be written as: $job = new SendOrderToVendor($order); $job->dispatchOn('orders'); (Exact function calls may not be correct, I'm on my phone) Functionally identical - same code path. The main gain is ergonomics, but it's entirely your choice how you prefer to write this code.
- motogpjimbo 3y agoThe issue isn't the exact syntax that's used to access the service object. It's the fact that any random chunk of code anywhere in the codebase can reach out to any other random piece of code. Syntactic sugar or not, that's considered to be an antipattern in pretty much any community outside of Laravel's.
- motogpjimbo 3y agoLaravel calls them "Facades". And no, they're not considered good practice outside the Laravel community.