Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

--TEST-- Test session_set_save_handler() : inheritance --INI-- session.save_handler=files ..

Decoded Output download

--TEST--
Test session_set_save_handler() : inheritance
--INI--
session.save_handler=files
session.name=PHPSESSID
--EXTENSIONS--
session
--SKIPIF--
<?php include('skipif.inc'); ?>
--FILE--
<?php

ob_start();

echo "*** Testing session_set_save_handler() : inheritance ***
";

class MySession3 extends SessionHandler {
    public $i = 0;
    public function open($path, $name): bool {
        ++$this->i;
        return parent::open($path, $name);
    }
    public function read($key): string|false {
        ++$this->i;
        return parent::read($key);
    }
}

class MySession4 extends MySession3 {
    public function write($id, $data): bool {
        $this->i = "hai";
        return parent::write($id, $data);
    }
}

$handler = new MySession3;
session_set_save_handler($handler);
session_start();

$_SESSION['foo'] = "hello";

session_write_close();
session_unset();

session_start();

var_dump($_SESSION, $handler->i);

session_write_close();
session_unset();

$handler = new MySession4;
session_set_save_handler($handler);

session_start();

$_SESSION['bar'] = 'hello';
session_write_close();
session_unset();

var_dump(session_id(), $_SESSION, $handler->i);
?>
--EXPECTF--
*** Testing session_set_save_handler() : inheritance ***
array(1) {
  ["foo"]=>
  string(5) "hello"
}
int(4)
string(%d) "%s"
array(2) {
  ["foo"]=>
  string(5) "hello"
  ["bar"]=>
  string(5) "hello"
}
string(3) "hai"

Did this file decode correctly?

Original Code

--TEST--
Test session_set_save_handler() : inheritance
--INI--
session.save_handler=files
session.name=PHPSESSID
--EXTENSIONS--
session
--SKIPIF--
<?php include('skipif.inc'); ?>
--FILE--
<?php

ob_start();

echo "*** Testing session_set_save_handler() : inheritance ***\n";

class MySession3 extends SessionHandler {
    public $i = 0;
    public function open($path, $name): bool {
        ++$this->i;
        return parent::open($path, $name);
    }
    public function read($key): string|false {
        ++$this->i;
        return parent::read($key);
    }
}

class MySession4 extends MySession3 {
    public function write($id, $data): bool {
        $this->i = "hai";
        return parent::write($id, $data);
    }
}

$handler = new MySession3;
session_set_save_handler($handler);
session_start();

$_SESSION['foo'] = "hello";

session_write_close();
session_unset();

session_start();

var_dump($_SESSION, $handler->i);

session_write_close();
session_unset();

$handler = new MySession4;
session_set_save_handler($handler);

session_start();

$_SESSION['bar'] = 'hello';
session_write_close();
session_unset();

var_dump(session_id(), $_SESSION, $handler->i);
?>
--EXPECTF--
*** Testing session_set_save_handler() : inheritance ***
array(1) {
  ["foo"]=>
  string(5) "hello"
}
int(4)
string(%d) "%s"
array(2) {
  ["foo"]=>
  string(5) "hello"
  ["bar"]=>
  string(5) "hello"
}
string(3) "hai"

Function Calls

None

Variables

None

Stats

MD5 301f340dab694645fe724b57ad223ae4
Eval Count 0
Decode Time 84 ms