note 123337 added to function.session-status

From: Date: Tue, 13 Nov 2018 09:05:21 +0000
Subject: note 123337 added to function.session-status
Groups: php.notes 
Request: Send a blank email to php-notes+get-209686@lists.php.net to get a copy of this message
Be careful when using session_status()-values and constants in an if-condition. My environment: - CentOS 7, - Apache2 (httpd) - PHP 7.2.12 My code was : if(session_status() === PHP_SESSION_NONE){ session_start(); } While debugging with xDebug, it went into the true-block while session_status() returned 2 (PHP_SESSION_NONE equals 1). Storing the return value into a variable and comparing against PHP_SESSION_NONE showed the same issue. After storing PHP_SESSION_NONE into another variable and comparing both variables, the issue got solved. I have no idea why the original comparision returned false-positive. So, im my case this was the solution: $session_status = session_status(); $session_none = PHP_SESSION_NONE; if($session_none === $session_status) { session_start(); } ---- Server IP: 208.43.231.9 Probable Submitter: 194.31.246.35 ---- Manual Page -- http://php.net/manual/en/function.session-status.php Edit -- https://master.php.net/note/edit/123337 Del: integrated -- https://master.php.net/note/delete/123337/integrated Del: useless -- https://master.php.net/note/delete/123337/useless Del: bad code -- https://master.php.net/note/delete/123337/bad+code Del: spam -- https://master.php.net/note/delete/123337/spam Del: non-english -- https://master.php.net/note/delete/123337/non-english Del: in docs -- https://master.php.net/note/delete/123337/in+docs Del: other reasons-- https://master.php.net/note/delete/123337 Reject -- https://master.php.net/note/reject/123337 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#209686) next »