Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dimitar032's avatar

Facades versus helper functions

Hello i was wondering which is better to use: " $request or request() " , " Auth:: facade or auth() " , " Session:: facade or session() " is there some different or it is the same i guess like a function is a little bit faster ?

0 likes
8 replies
jlrdw's avatar

Sense in the background they are the same you could go either way. I prefer the long way

$value = $request->session()->get('key');
moka's avatar

Helpers just require less typing.

SaeedPrez's avatar

I believe a difference would be facades are mockable for testing where helpers are not, but I'm not even sure about helpers not being mockable, so at the end of the day, I really don't know anything about this and you can just ignore my post ☺

9 likes
jlrdw's avatar

@SaeedPrez now that's funny, you may even get a best answer for that reply.

1 like
SaeedPrez's avatar

@jlrdw hehe, have to be honest ☺ I don't want to give anyone any false info

jlrdw's avatar

@SaeedPrez I didn't think about the testing part. I do most of my testing old fashion way, like if a query computes something, I crunch the numbers in MS Excel to ensure the query is correct prior to calling it good. As you know a join / group by query can give wrong results.

SaeedPrez's avatar

@jlrdw you should definitely check out the testing series if you haven't already. It can't get easier than writing for example $this->assertEquals(1, App\Model::count())

sandervanhooft's avatar

To the best of my knowledge, the helper method would resolve the binding using the facade reference.

If you override the binding with a mock object in your test, (SomeFacade::fake()), all binding instances for that class should be overridden with the mock, including the one called by the helper function.

1 like

Please or to participate in this conversation.