cphalcon: $app->persistent (Session bag) fatal error on 3.2.0 (Invalid superglobal)

Expected and Actual Behavior

Trying to use persistent global variable as usual in Phalcon Micro

Now this is truly “the bug”. Everything working fine on 3.1.2. From 3.2.0 entire app breaks with fatal error.

2017/06/21 12:36:13 [error] 399#399: *209 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Exception: Invalid superglobal in /var/www/html/api/public/tryout.php:22
Stack trace:
#0 [internal function]: Phalcon\Session\Adapter->get('Phalcon\\Mvc\\Mic...')
#1 [internal function]: Phalcon\Session\Bag->initialize()
#2 [internal function]: Phalcon\Session\Bag->set('auditID', 1)
#3 /var/www/html/api/public/tryout.php(22): Phalcon\Session\Bag->__set('auditID', 1)
#4 {main}
  thrown in /var/www/html/api/public/tryout.php on line 22" while reading response header from upstream, client: 178.xxx.xxx.xx, server: mytld.com, request: "GET /tryout.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "mytld.com:9005"

Provide minimal script to reproduce the issue

$app = new \Phalcon\Mvc\Micro();
$app->get(
    "/say/hello/{name}",
    function ($name) {
        echo "<h1>Hello! $name</h1>";
    }
);
$app->persistent->auditID = 1;

Details

  • Phalcon version: (3.2.0)
  • PHP Version: (PHP 7.0.18)
  • Operating System: Debian GNU/Linux
  • Installation type: Compiling from source
  • Zephir version (if any): (0.9.8-6335775f25)
  • Server: Nginx
  • Other related info (Database, table schema): n/a

Everything working fine on 3.1.2. From 3.2.0 entire app breaks with fatal error.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 24 (24 by maintainers)

Most upvoted comments

Also to add - why this is 100% correct exception for me and it’s actually feature - not a bug. If you do var_dump($_SESSION) in php without session_start you will have Notice: Undefined variable: _SESSION. Then pretty obvious zephir don’t recognize _SESSION and it’s invalid superglobal indeed because it’s just undefined and not initialized by session_start

Imho the best will be in Phalcon 4 to remove session from FactoryDefault and don’t check in any method if session was started - just developer have to start it when defining service, adding overhead by checking if it was started and if not - start it is kind of bad.