Var_dump from int shows UNKNOWN: 0

I found something that I have never seen before in PHP. My script aborts with an error:

Fatal error: unsupported operand types at ... on line 41

The error message refers to the following expression:

if($this->lastAction + 7200 <= time()) {
}

      

When I var_dump $this->lastAction

before an operation in my script, I get the output:

UNKNOWN:0

      

I've never seen this before. And I can't imagine where this value is assigned to my variable or under what conditions it happens.

Is there a clue or explanation as to where this "value" comes from?

UPDATE 1

I found out that if I run the same installation in env with PHP 5.3, I get the error instead:

Object of class stdClass cannot be converted to int ... on line 41

But I have never assigned an instance stdClass

to this variable.

UPDATE 2

The problem also exists in PHP 5.5.19

with the same error as the version 5.4.28

.


AuthHandler.php

abstract class AuthHandler
{
    protected $lastAction;

    public function __construct()
    {
         $this->lastAction = isset($_SESSION['last_action']) ? $_SESSION['last_action'] : time();

         if($this->lastAction + 7200 <= time()) {
             $this->logout();
         }

         $this->lastAction = time();
    }

    public function logout()
    {
        session_destroy();
        session_regenerate_id();

        $this->lastAction = null;
    }

    public function __destruct()
    {
        $_SESSION['last_action'] = $this->lastAction;
    }
}

      

DBAuthHandler.php

class DBAuthHandler extends AuthHandler
{
    // other stuff here
}

      

+3


source to share


2 answers


Well, this is not a definitive answer, but it may shed light on the problem.

PHP source check, "unknown type" is the default case in the gettype function . The same is true for the var_dump function .

So, basically, when a variable is not NULL, boolean, integer, double, string, array, object or resource, then it is an unknown type .

I've seen this happen when a pointer becomes invalid.

$handle = fopen('file.txt','r');
echo gettype($handle); // resource
fclose($handle);
echo gettype($handle); // unknown

      




Since time () always returns an integer (or at least it should), the problem must lie with $_SESSION['last_action']

.

Even using multiple methods for destruction $_SESSION

, I was unable to reproduce your problem.

It might help if you run a backtrace $_SESSION['last_action']

, periodically checking its value.

+1


source


The code you provided works great for me. Returned object

object(App\Http\Controllers\DBAuthHandler)#141 (1) { ["lastAction":protected]=> int(1416817485) } 

      



So, the problem will be in the method that is trying to install $_SESSION['last_action']

.

0


source







All Articles