Skip to content

Review parameter names in ext/session #6239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions ext/session/session.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,45 @@ function session_commit(): bool {}
* @param callable|object $open
* @param callable|bool $close
*/
function session_set_save_handler($open, $close = UNKNOWN, callable $read = UNKNOWN, callable $write = UNKNOWN, callable $destroy = UNKNOWN, callable $gc = UNKNOWN, callable $create_sid = UNKNOWN, callable $validate_sid = UNKNOWN, callable $update_timestamp = UNKNOWN): bool {}
function session_set_save_handler(
$open,
$close = UNKNOWN,
callable $read = UNKNOWN,
callable $write = UNKNOWN,
callable $destroy = UNKNOWN,
callable $gc = UNKNOWN,
callable $create_session_id = UNKNOWN,
callable $validate_session_id = UNKNOWN,
callable $update_timestamp = UNKNOWN
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are called create_sid(), validateId() and updateTimestamp() in the SessionHandler interface -- yes, complete with inconsistent name casing. I was going to suggest that we should match those names here, but given the casing issue I'm not sure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea here either. I can revert to using the original names here until we decide it.

): bool {}

function session_cache_limiter(?string $cache_limiter = null): string|false {}

function session_cache_expire(?int $new_cache_expire = null): int|false {}

function session_set_cookie_params(array|int $lifetime_or_options, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httponly = null): bool {}
function session_set_cookie_params(array|int $lifetime_or_options, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httponly = null): bool {}

function session_start(array $options = []): bool {}

interface SessionHandlerInterface
{
/** @return bool */
public function open(string $save_path, string $session_name);
public function open(string $path, string $name);

/** @return bool */
public function close();

/** @return string */
public function read(string $key);
public function read(string $id);

/** @return bool */
public function write(string $key, string $val);
public function write(string $id, string $value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function write(string $id, string $value);
public function write(string $id, string $data);

Possibly, as you use $data in session_decode.

Copy link
Member Author

@kocsismate kocsismate Sep 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! We could also use $content maybe (although I prefer data here), as asked in #6238 (comment). Can we then standardize on using $data as a name for similar params? :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think $data is better than $content. I think you need to change updateTimestamp() to use it as well. At least based on docs, the argument there seems to have the same meaning.


/** @return bool */
public function destroy(string $key);
public function destroy(string $id);

/** @return int|bool */
public function gc(int $maxlifetime);
public function gc(int $lifetime);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it still have the same meaning? Could we use TTL? I think lifetime has too widespread usage to change it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the TTL idea, but there's also the consideration that this is the value specified by session.gc_maxlifetime.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left this as $lifetime, but I'm ok to revert this to $maxlifetime or $max_lifetime if you prefer these.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mild preference for $max_lifetime from my side.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, seems good for me as well. And I've just pushed a commit with this.

}

interface SessionIdInterface
Expand All @@ -83,31 +93,31 @@ public function create_sid();
interface SessionUpdateTimestampHandlerInterface
{
/** @return bool */
public function validateId(string $key);
public function validateId(string $id);

/** @return bool */
public function updateTimestamp(string $key, string $val);
public function updateTimestamp(string $id, string $value);
}

class SessionHandler implements SessionHandlerInterface, SessionIdInterface
{
/** @return bool */
public function open(string $save_path, string $session_name) {}
public function open(string $path, string $name) {}

/** @return bool */
public function close() {}

/** @return string */
public function read(string $key) {}
public function read(string $id) {}

/** @return bool */
public function write(string $key, string $val) {}
public function write(string $id, string $value) {}

/** @return bool */
public function destroy(string $key) {}
public function destroy(string $id) {}

/** @return int|bool */
public function gc(int $maxlifetime) {}
public function gc(int $lifetime) {}

/** @return string */
public function create_sid() {}
Expand Down
18 changes: 9 additions & 9 deletions ext/session/session_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 9bdf602c14822b13553a5214a415e312c21cd30c */
* Stub hash: 4ae16a4aef8d9c89a7888b44ef300d6f658add78 */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_session_name, 0, 0, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, name, IS_STRING, 1, "null")
Expand Down Expand Up @@ -64,8 +64,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_session_set_save_handler, 0, 1,
ZEND_ARG_TYPE_INFO(0, write, IS_CALLABLE, 0)
ZEND_ARG_TYPE_INFO(0, destroy, IS_CALLABLE, 0)
ZEND_ARG_TYPE_INFO(0, gc, IS_CALLABLE, 0)
ZEND_ARG_TYPE_INFO(0, create_sid, IS_CALLABLE, 0)
ZEND_ARG_TYPE_INFO(0, validate_sid, IS_CALLABLE, 0)
ZEND_ARG_TYPE_INFO(0, create_session_id, IS_CALLABLE, 0)
ZEND_ARG_TYPE_INFO(0, validate_session_id, IS_CALLABLE, 0)
ZEND_ARG_TYPE_INFO(0, update_timestamp, IS_CALLABLE, 0)
ZEND_END_ARG_INFO()

Expand All @@ -90,26 +90,26 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_session_start, 0, 0, _IS_BOOL, 0
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SessionHandlerInterface_open, 0, 0, 2)
ZEND_ARG_TYPE_INFO(0, save_path, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, session_name, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, path, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SessionHandlerInterface_close, 0, 0, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SessionHandlerInterface_read, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, id, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SessionHandlerInterface_write, 0, 0, 2)
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, val, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, id, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0)
ZEND_END_ARG_INFO()

#define arginfo_class_SessionHandlerInterface_destroy arginfo_class_SessionHandlerInterface_read

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SessionHandlerInterface_gc, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, maxlifetime, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, lifetime, IS_LONG, 0)
ZEND_END_ARG_INFO()

#define arginfo_class_SessionIdInterface_create_sid arginfo_class_SessionHandlerInterface_close
Expand Down