PHP 8.6.0 Beta 2 available for testing

Yaf_Session::offsetGet

(Yaf >=1.0.0)

Yaf_Session::offsetGetGet a session value (ArrayAccess)

Description

public function Yaf_Session::offsetGet(mixed $name): mixed

Retrieves a session value by key. This method is an alias of Yaf_Session::get() and is called when array syntax is used to read a session object.

Parameters

name

The session key to retrieve.

Return Values

The session value, or null if the key does not exist.

Examples

Example #1 Yaf_Session::offsetGet() example

<?php
class IndexController extends Yaf_Controller_Abstract
{
    public function indexAction()
    {
        $session = Yaf_Session::getInstance();
        $session->start();

        // reading with array syntax calls offsetGet()
        $userId = $session["user_id"];
        if ($userId === null) {
            return $this->redirect("/account/login");
        }

        echo "logged in as user #", $userId;
    }
}
?>

See Also

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top