1
0
mirror of https://github.com/php/php-src.git synced 2026-04-21 06:51:18 +02:00
Files
archived-php-src/ext/session/tests/session_set_save_handler_iface_002.phpt
Peter Kokot b746e69887 Sync leading and final newlines in *.phpt sections
This patch adds missing newlines, trims multiple redundant final
newlines into a single one, and trims redundant leading newlines in all
*.phpt sections.

According to POSIX, a line is a sequence of zero or more non-' <newline>'
characters plus a terminating '<newline>' character. [1] Files should
normally have at least one final newline character.

C89 [2] and later standards [3] mention a final newline:
"A source file that is not empty shall end in a new-line character,
which shall not be immediately preceded by a backslash character."

Although it is not mandatory for all files to have a final newline
fixed, a more consistent and homogeneous approach brings less of commit
differences issues and a better development experience in certain text
editors and IDEs.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
[2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2
[3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
2018-10-15 04:32:30 +02:00

90 lines
2.1 KiB
PHP

--TEST--
Test session_set_save_handler() function: interface wrong
--INI--
session.save_handler=files
session.name=PHPSESSID
--SKIPIF--
<?php include('skipif.inc'); ?>
--FILE--
<?php
ob_start();
/*
* Prototype : bool session_set_save_handler(SessionHandlerInterface $handler [, bool $register_shutdown_function = true])
* Description : Sets user-level session storage functions
* Source code : ext/session/session.c
*/
echo "*** Testing session_set_save_handler() function: interface wrong ***\n";
interface MySessionHandlerInterface {
public function open($path, $name);
public function close();
public function read($id);
public function write($id, $data);
public function destroy($id);
public function gc($maxlifetime);
}
class MySession2 implements MySessionHandlerInterface {
public $path;
public function open($path, $name) {
if (!$path) {
$path = sys_get_temp_dir();
}
$this->path = $path . '/u_sess_' . $name;
return true;
}
public function close() {
return true;
}
public function read($id) {
return (string)@file_get_contents($this->path . $id);
}
public function write($id, $data) {
echo "Unsupported session handler in use\n";
}
public function destroy($id) {
@unlink($this->path . $id);
}
public function gc($maxlifetime) {
foreach (glob($this->path . '*') as $filename) {
if (filemtime($filename) + $maxlifetime < time()) {
@unlink($filename);
}
}
return true;
}
}
function good_write($id, $data) {
global $handler;
echo "good handler writing\n";
return file_put_contents($handler->path . $id, $data);
}
$handler = new MySession2;
$ret = session_set_save_handler(array($handler, 'open'), array($handler, 'close'),
array($handler, 'read'), 'good_write', array($handler, 'destroy'), array($handler, 'gc'));
var_dump($ret);
$ret = session_set_save_handler($handler);
var_dump($ret);
session_start();
--EXPECTF--
*** Testing session_set_save_handler() function: interface wrong ***
bool(true)
Warning: session_set_save_handler() expects parameter 1 to be SessionHandlerInterface, object given in %s
bool(false)
good handler writing