Silex Bridge to Old-Style PHP Sessions ($_SESSION)

I am exploring the Silex framework. I am trying to gently evolve a very nice app from “old school PHP” to “new school PHP”. I have chosen Silex (atop Symfony) as my first framework to try. I like Silex so far because it helps me without lecturing me. I cannot rewrite my whole app overnight – I need to evolve to a Silex App, one feature at a time.

This code uses the Symfony PhpBridgeSessionStorage – and it makes me very happy.


// http://localhost:8888/silex/hello/bob

use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorage;

require_once "vendor/autoload.php";

$session = new Session(new PhpBridgeSessionStorage());
$app = new Silex\Application();
$app['session'] = $session;

$app->get('/hello/{name}', function ($name) use ($app) {
    // New Session
    if ( $app['session']->has('y') ) {
        $app['session']->set('y', $app['session']->get('y')+1);
    } else {
        $app['session']->set('y', 20);

    // Read and write old session
    if ( isset($_SESSION['x'])) {
    } else {
        $_SESSION['x'] = 42;

    return "<p>Hello $name</p>\n";