# PHP_SESSION_* constant values

- Thread: https://externals.io/message/57541
- Original archive: https://news-web.php.net/php.internals/57541
- Started by Justin Martin on 2012-01-28T19:17:40+00:00
- Messages: 9
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #57541 — Justin Martin — 2012-01-28T19:17:40+00:00

URL: https://externals.io/message/57541#57541

Hello everyone,

For the result of `session_status()`, the corresponding constants for the 
sessions state are

   - `PHP_SESSION_DISABLED` = 0
   - `PHP_SESSION_NONE` = 1
   - `PHP_SESSION_ACTIVE` = 2

I'd like to suggest we change these values to

   - `PHP_SESSION_DISABLED` = -1
   - `PHP_SESSION_NONE` = 0
   - `PHP_SESSION_ACTIVE` = 1

This way, one can do if(session_status()) to check if there is an active 
session, rather than having to compare the result to a constant.

Any objections?

Thanks,
Justin Martin

---

## #57542 — Paul Dragoonis — 2012-01-28T20:43:01+00:00

URL: https://externals.io/message/57541#57542 · In reply to: #57541

> Hello everyone,
>
> For the result of `session_status()`, the corresponding constants for the
> sessions state are
>
>  - `PHP_SESSION_DISABLED` = 0
>  - `PHP_SESSION_NONE` = 1
>  - `PHP_SESSION_ACTIVE` = 2
>
> I'd like to suggest we change these values to
>
>  - `PHP_SESSION_DISABLED` = -1
>  - `PHP_SESSION_NONE` = 0
>  - `PHP_SESSION_ACTIVE` = 1
>
> This way, one can do if(session_status()) to check if there is an active
> session, rather than having to compare the result to a constant.
>
> Any objections?

I believe comparing the value against a constant, is always more
readable than wondering what "truthy" means. if(session_status() ===
PHP_SESSION_ACTIVE) is much self-documenting than the proposed change.

Therefore I object to this change.

- Paul

>
> Thanks,
> Justin Martin

---

## #57544 — Stas Malyshev — 2012-01-28T21:10:00+00:00

URL: https://externals.io/message/57541#57544 · In reply to: #57541

Hi!

> I'd like to suggest we change these values to
>
>     - `PHP_SESSION_DISABLED` = -1
>     - `PHP_SESSION_NONE` = 0
>     - `PHP_SESSION_ACTIVE` = 1
>
> This way, one can do if(session_status()) to check if there is an active
> session, rather than having to compare the result to a constant.
>
> Any objections?

Yes, there's no reason to do that since you can just compare to the 
constant - that's why they exist in the first place. Then gain of not 
typing couple of characters is much less than the confusion that would 
result from changing the constants.
-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

---

## #57545 — Sanford Whiteman — 2012-01-28T21:14:16+00:00

URL: https://externals.io/message/57541#57545 · In reply to: #57542

> I believe comparing the value against a constant, is always more
> readable than wondering what "truthy" means. if(session_status() ===
> PHP_SESSION_ACTIVE) is much self-documenting than the proposed change.

...  also  an  obvious  BC  break  for anyone who was using the values
instead  of the constants before. Not that anyone should ever do this,
but  the  change  presupposes  that  people *do* use the values, so it
basically  contradicts  its  own  acceptability  as  it  is a breaking
change!

-- S.

---

## #57546 — Paul Dragoonis — 2012-01-28T21:18:29+00:00

URL: https://externals.io/message/57541#57546 · In reply to: #57545

On Sat, Jan 28, 2012 at 9:14 PM, Sanford Whiteman
<swhitemanlistens-software@cypressintegrated.com> wrote:
> > […]
>
> ...  also  an  obvious  BC  break  for anyone who was using the values
> instead  of the constants before. Not that anyone should ever do this,
> but  the  change  presupposes  that  people *do* use the values, so it
> basically  contradicts  its  own  acceptability  as  it  is a breaking
> change!

There is no BC change here as `session_status()` has been added in the
5_4 branch as far as i can tell.

>
> -- S.

---

## #57547 — Sanford Whiteman — 2012-01-28T21:46:07+00:00

URL: https://externals.io/message/57541#57547 · In reply to: #57546

> There is no BC change here as `session_status()` has been added in the
> 5_4 branch as far as i can tell.

OK, fair enough, I didn't understand it was trying to get into 5.4.

-- S.

---

## #57548 — Justin Martin — 2012-01-28T21:53:20+00:00

URL: https://externals.io/message/57541#57548 · In reply to: #57541

Someone actually just pointed out to me that if(-1) returns true. In 
that case, I suppose my suggestion doesn't quite work.

The reason I suggest this is that I suspect people will constantly be 
looking up what the constants are called.


> Hello everyone,
>
> For the result of `session_status()`, the corresponding constants for the
> sessions state are
>
> - `PHP_SESSION_DISABLED` = 0
> - `PHP_SESSION_NONE` = 1
> - `PHP_SESSION_ACTIVE` = 2
>
> I'd like to suggest we change these values to
>
> - `PHP_SESSION_DISABLED` = -1
> - `PHP_SESSION_NONE` = 0
> - `PHP_SESSION_ACTIVE` = 1
>
> This way, one can do if(session_status()) to check if there is an active
> session, rather than having to compare the result to a constant.
>
> Any objections?
>
> Thanks,
> Justin Martin

---

## #57550 — Sanford Whiteman — 2012-01-28T22:03:11+00:00

URL: https://externals.io/message/57541#57550 · In reply to: #57548

> Someone actually just pointed out to me that if(-1) returns true. In
> that case, I suppose my suggestion doesn't quite work.

Well,  it  still "works" depending on what conclusion you want to draw
in your local environment.

Sessions_disabled || yes_active_session might go through the same code
path, while no_active_session might go through another.

-- S.

---

## #57552 — Paul Dragoonis — 2012-01-28T22:59:42+00:00

URL: https://externals.io/message/57541#57552 · In reply to: #57548

> Someone actually just pointed out to me that if(-1) returns true. In that
> case, I suppose my suggestion doesn't quite work.
>
> The reason I suggest this is that I suspect people will constantly be
> looking up what the constants are called.

Encouraging people to check the manual is a good thing.

As the constants are being used the user doesn't need to consult the
manual at all as `PHP_SESSION_DISABLED` is very self-documenting.

Again, a -1 from me.

- Paul.

>
> 
> > […]
