Skip to content
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

Notice: Undefined variable: _SESSION #10530

Closed
duythien opened this issue Jun 22, 2015 · 3 comments
Closed

Notice: Undefined variable: _SESSION #10530

duythien opened this issue Jun 22, 2015 · 3 comments

Comments

@duythien
Copy link
Contributor

Hi Team

When I update to version 2.0.3

[root@dev ext]# php --re phalcon | grep "version"
Extension [ <persistent> extension #38 phalcon version 2.0.3 ] {
        Property [ protected static $_version ]
[root@dev ext]# 

I get error Notice: Undefined variable: _SESSION in file ..... Below the my config


// Start the session the first time some component request the session service
$di->set(
    'session',
    function () use ($di) {
        $sessionAdapter = $di->get('config')->application->session->adapter;
        $session        = new $sessionAdapter($di->get('config')->application->session->options->toArray());
        $session->start();

        return $session;
    },
    true
);

It not working, but if i add session_start(); it will working

// Start the session the first time some component request the session service
$di->set(
    'session',
    function () use ($di) {
        $sessionAdapter = $di->get('config')->application->session->adapter;
        $session        = new $sessionAdapter($di->get('config')->application->session->options->toArray());
        $session->start();

        return $session;
    },
    true
);
session_start()

Is it bug ?

@sergeyklay
Copy link
Contributor

$di->setShared('session', function () use ($config) {
    $sessionConfig = $config->session->toArray();
    $adapter = '\Phalcon\Session\Adapter\\' . $sessionConfig['adapter'];
    unset($sessionConfig['adapter']);

    /** @var \Phalcon\Session\AdapterInterface $session */
    $session = new $adapter($sessionConfig);
    $session->start();

    return $session;
});

@andresgutierrez
Copy link
Contributor

You don't have to access _SESSION super global directly, you have to use $this->session->set/$this->session->set so the service will be initialized the first time it's used.

@duythien
Copy link
Contributor Author

Ok, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants