On 28 July 2017 14:37:10 BST, "li...@rhsoft.net" <li...@rhsoft.net> wrote:
>(Arguably, all the other superglobals should be read only for the same
>reason, but that would be a huge break now.)
>
>make them readonly would break my whole codebase 

Yes, I only meant that as an absolutely hypothetical "if I had a time machine 
and could design it a different way...", I realise it would break everything to 
change it now.


>> If I understand you right, the scenario you describe is "I don't want
>to start a session yet, but if and when I do, I want to put this data
>into it". It feels like that could be adequately handled in userland
>with a wrapper object (or global var and functions if you prefer),
>which reads to and from $_SESSION when a session is open, but a a
>holding array when it's not yet.
>
>that don't work because at this point you don't know in userland if you
>started a completly new session which should be initialized with values
>for follow-up requests or use the existing values from a previous 
>request - at least not without writing ugly code

Do you mean like this?

session_start();
if ( ! $_SESSION['initialised'] ) {
    $_SESSION['initialised'] = true;
    foreach ( $this->session_init_vars as $var => $val ) {
        $_SESSION[ $var ] = $val;
    }
}


That should work as long as you don't run session_start() outside that 
function, and centralising that is already necessary to avoid "already started" 
errors.

Regards,

-- 
Rowan Collins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to