Symfony vs Laravel: Explicit Dependency Injection and Facades

A comparison of Symfony's explicit dependency injection and compiled container with Laravel facades, based on long-running PHP codebases I've worked on.

· 3 min read · Erik Kubica

In the PHP ecosystem, Laravel is the more popular framework.

It has excellent documentation, a lively community, and a large ecosystem of first-party add-ons. If you want to build an MVP quickly, Laravel is a pleasure to work with.

Across thirteen years of building long-lived systems, though, I have often preferred Symfony for projects that need to be maintained for years.

The question I ask is whether the framework optimizes for developer convenience on day one, or for maintainability on year five. Both are valid goals, and I've used both frameworks happily.

Laravel's Facades

Laravel gets its developer ergonomics from PHP's dynamic features: facades, magic methods (__callStatic), and global service locators.

The code looks concise:

// Typical Laravel controller method
class OrderController extends Controller {
    public function store(Request $request) {
        $user = Auth::user();
        Cache::put('order_'.$user->id, $request->all(), 300);
        Mail::to($user)->send(new OrderConfirmed());
        return response()->json(['status' => 'queued']);
    }
}

It reads almost like plain English. The trade-off is that some things are hidden.

Auth::user() is a static facade that looks up global state. When you write automated tests, you can't pass a mock user through a constructor; you call Auth::shouldReceive() to change framework internals. (Laravel's testing helpers make this workable, and many teams are fine with it.)

Static analysis tools like PHPStan or Psalm need extensions like Larastan to follow the magic proxies.

On a large codebase, refactoring a method name can feel risky when your IDE can't always trace magic static calls.

Symfony: Explicit Dependency Injection

In Symfony, if a service needs to send emails, query database records, or use a cache, it declares those dependencies in its constructor:

namespace App\Service;

use Psr\Log\LoggerInterface;
use Symfony\Contracts\Cache\CacheInterface;

class OrderProcessor {
    public function __construct(
        private readonly CacheInterface $cache,
        private readonly LoggerInterface $logger,
        private readonly InvoiceGenerator $invoices
    ) {}

    public function process(int $userId, array $items): OrderResult {
        $this->logger->info('Processing order', ['user_id' => $userId]);
        $invoice = $this->invoices->generate($userId, $items);
        return new OrderResult($invoice->getId());
    }
}

That class has no coupling to Symfony HTTP kernel classes. It is a plain PHP object that you can instantiate in a unit test with simple mocks:

$processor = new OrderProcessor($mockCache, $mockLogger, $mockInvoices);

Symfony Messenger follows a similar approach. Instead of tying job dispatching to a specific queue worker, Symfony defines message buses around plain PHP message objects. You dispatch a message, and whether it executes synchronously in memory, goes to AMQP, or is routed to Redis is a configuration decision, separate from your business logic.

For me, Laravel has been the faster way to start, and Symfony the easier one to maintain over a longer time. Your team and project may weigh that differently.

Compile-Time Container Verification

Symfony's dependency injection container is compiled.

When you deploy a Symfony application and run php bin/console cache:warmup, Symfony parses your service configuration, resolves the autowired type-hints, and compiles the dependency graph into a single optimized PHP file in var/cache/prod/.

If someone forgot to bind an interface, configured a circular dependency, or used an invalid constructor argument, the build fails in your terminal during cache warmup. On one project:

  • Container Compilation Speed: 1,400 registered services compiled in 420 ms.
  • Static Analysis Compliance: Clean passes on PHPStan Level 8 without magic helpers.
  • Runtime Execution: No dynamic container lookups; service wiring is plain compiled PHP.

Laravel is a good choice, especially for smaller teams and quick delivery. For backends that several teams will maintain for years, I have found Symfony's explicitness worth the extra typing, though it is a matter of taste and team habits as much as technology.

Tell me what you need built

Usually a reply within a day, by email or WhatsApp.