peachpiecompiler / peachpie

PeachPie - the PHP compiler and runtime for .NET and .NET Core
https://www.peachpie.io
Apache License 2.0
2.31k stars 201 forks source link

can not access the session variable if the session is not auto start. #1092

Open pmt66 opened 1 year ago

pmt66 commented 1 year ago

If the session is not set auto start at:

class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddPhp(options =>
            {
                //options.Session.AutoStart = true; //<==
            });

Although I call session_start() before access session variable like this:

//php
session_start();
$_SESSION['count']=0; // throw error here

It throw error > System.NullReferenceException: Object reference not set to an instance of an object.

I have not found this error for v1.1.0 ,v1.1.1 but found this error for v1.1.2, v1.1.3 I use net5.0

jakubmisek commented 1 year ago

thank you for reporting the issue;

This may happen if there are headers sent before calling session_start(). Isn't there anything in the debug log?

jakubmisek commented 1 year ago

also; please check what is the return value of session_start() - it's probably returning false with some additional details in debug output.