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

Undefined variable: _SESSION in command php spark #1183

Closed
HieuPT7 opened this issue Aug 27, 2018 · 4 comments
Closed

Undefined variable: _SESSION in command php spark #1183

HieuPT7 opened this issue Aug 27, 2018 · 4 comments

Comments

@HieuPT7
Copy link
Contributor

HieuPT7 commented Aug 27, 2018

Hi
I'm run command php spark then error

HieuPT-Macbook:HieuPT$ php spark 

CodeIgniter CLI Tool - Version 4.0-dev - Server-Time: 2018-08-27 11:47:53am


An uncaught Exception was encountered

Type:        ErrorException
Message:     Undefined variable: _SESSION
Filename:    /Applications/.../htdocs/.../system/Session/Session.php
Line Number: 474

You can view it here: http://prntscr.com/knhgmn
thanks

@lonnieezell
Copy link
Member

I'm not getting that with the latest build locally. Have you been working on any custom commands? What OS are you on?

@HieuPT7
Copy link
Contributor Author

HieuPT7 commented Aug 27, 2018

Oh, I found it
In my filter, i'm using session, it causes errors.

App/Filters/AdminAuthFilter.php

<?php namespace App\Filters;

use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Filters\FilterInterface;

class AdminAuthFilter implements FilterInterface
{
    public function before(RequestInterface $request)
    {
        // Do something here
        service('session')->start();
        // Do something here
        return true;
    }

    //--------------------------------------------------------------------

    public function after(RequestInterface $request, ResponseInterface $response)
    {
        // Do something here
    }
}

Config/Filters.php

<?php namespace Config;

use CodeIgniter\Config\BaseConfig;

class Filters extends BaseConfig
{
	// Makes reading things below nicer,
	// and simpler to change out script that's used.
	public $aliases = [
		'csrf' 	  => \App\Filters\CSRF::class,
		'toolbar' => \App\Filters\DebugToolbar::class,
		'honeypot' => \App\Filters\Honeypot::class,
		'admin' => \App\Filters\AdminAuthFilter::class,
	];

	// Always applied before every request
	public $globals = [
		'before' => [
			'admin'
			// 'csrf',
		],
		'after'  => [
			// 'admin',
			//'honeypot'
		]
	];
.......

@samsonasik
Copy link
Member

you should can add is_cli() check for that:

helper('is_cli');
if (! is_cli()) {
    //...
}

@lonnieezell
Copy link
Member

Correct - check for CLI in your filter. Not a bug since SESSIONS don't exist in the CLI version of PHP.

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