Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<Yaf_Session::getYaf_Session::has>
^Yaf_SessionLast updated: Mon, 26 Oct 2026

Yaf_Session::getInstance

(Yaf >=1.0.0)

Yaf_Session::getInstance — Get the session singleton

Description

public static function Yaf_Session::getInstance(): Yaf_Session

Returns the singleton Yaf_Session instance, creating it if necessary. The session is started automatically on first access.

Parameters

This function has no parameters.

Return Values

The Yaf_Session singleton instance, or null if the session could not be started.

Examples

Example #1 Yaf_Session::getInstance() example

<?php
$session = Yaf_Session::getInstance();
$session->start();
$session->set("user_id", 42);

// ... later, elsewhere in the application
$same = Yaf_Session::getInstance();

var_dump($same === $session);
var_dump($same->get("user_id"));
?>

The above example will output something similar to:

bool(true)
int(42)

See Also


<Yaf_Session::getYaf_Session::has>
^Yaf_SessionLast updated: Mon, 26 Oct 2026