NYCPHP Meetup

NYPHP.org

Subject: Re: [nycphp-talk] PHP 4.3.3 and session_start

Emmanuel Décarie emm at scriptdigital.com
Thu Feb 26 23:55:17 EST 2004


From: Chris Shiflett <shiflett at php.net>
>--- Emmanuel DÈcarie <emm at scriptdigital.com> wrote:
>> I'd like to know why in the world, starting with PHP 4.3.3, PHP need
>> to throw an error (E_NOTICE) when it encounter a second session_start
>
>This seems like the right thing for PHP to do, in my opinion.
>
>> But really, I don't understand the logic behind this change. If the
>> second session_start is to be ignored, why then throw an error?
>
>I hate to sound unsympathetic, but a warning seems appropriate. PHP will
>still do what you're wanting, but there's no reason to have multiple
>session_start() calls, so it's just letting you know.

>It seems like you have your error reporting set very strict, but you want
>your code to be sloppy. You have to pick one or the other. If you don't
>care whether your code is sloppy, set your error reporting differently.

Thanks for the answer Chris. But I disagree with you. I could be wrong though
and willing to learn why.

Here's my scenario. I work for a learning institution that produce on-line
courses. They asked me to plug on the already existing courses an access control
framework. The control access framework is easy to plug on top of these courses,
it’s just two includes in the pages to be protected.

Some of these courses are starting a session and some not. Since the access
framework need to start a session and is called first, PHP will throw an error
when it will encounter a session_start in the courses that need a session.

Because these courses where produced by different programmers working for
different shops, I need to ask them to modify their code and check first if a
session already exists before calling session_start. This is not fun.

I can understand the point that for now on, I should  always in my code check
first if a session exists. But what about existing code base like in my
scenario?

Maybe my line of reasoning is wrong but I never heard that there was a penalty
when PHP encountered a second session_start (). What I know is that PHP will
disregard the second session_start, doing something similar I guess to
include_once when it encounter a file that was already included.

If there is no penalty calling multiple times session_start, why PHP should
throw an error when this behavior might break compatibilities with existing
code?

Cheers
-Emmanuel
--
Emmanuel Décarie / Programmation pour le Web - Programming for the Web
<http://scriptdigital.com/> - Blog: <http://blog.scriptdigital.com> - AIM: scriptdigital



More information about the talk mailing list