php8.5
Home/ Manual/ yaf / yaf_registry/ Yaf_Registry::__construct

Yaf_Registry::__construct

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Constructor of Yaf_Registry

Description

Yaf_Registry::__construct()

The constructor is private: Yaf_Registry implements the singleton pattern and cannot be instantiated directly. Use the static methods to read and write registry entries.

Parameters Parameters

Return Values

No value is returned.

Examples

Yaf_Registry::__construct example

The constructor is private, so direct instantiation is rejected:

php
<?php
$registry = new Yaf_Registry();
?>

The above example will output something similar to:

output
PHP Fatal error:  Uncaught Error: Call to private Yaf_Registry::__construct() from invalid context

Using Yaf_Registry through its static methods

php
<?php
Yaf_Registry::set("version", Yaf_Application::app()->getConfig()->application->version);
var_dump(Yaf_Registry::get("version"));
?>

The above example will output something similar to:

output
string(7) "1.0.0.1"

See Also

  • Yaf_Registry::set
  • Yaf_Registry::get
  • Yaf_Registry::has

Source: reference/yaf/yaf_registry/construct.xml · from the official PHP manual (php/doc-en)