PHP 8.6.0 Beta 3 is available for testing

Yaconf::has

(PECL yaconf >= 1.0.0)

Yaconf::hasCheck whether a configuration value exists

Description

public static function Yaconf::has(string $name): bool

Determines whether a configuration value exists under name, which uses the same dot notation as Yaconf::get(): for example, "app.name" or, since Yaconf 1.2.0, "users.database.master" for files in sub-directories.

Parameters

name

The configuration name to look up, using dot notation to traverse nested keys, for example "app.name" or "users.database.master".

Return Values

Returns true if a configuration value exists at name, false otherwise.

Examples

The examples below assume an app.ini placed in the directory configured with yaconf.directory, holding the keys name="shop" and debug=0.

Example #1 Yaconf::has() example

<?php
var_dump(Yaconf::has("app.name"));     // bool(true)
var_dump(Yaconf::has("app.missing"));  // bool(false)

// useful to distinguish a stored empty value from a missing key,
// where Yaconf::get() would return the same default for both
if (Yaconf::has("app.debug")) {
    $debug = (bool) Yaconf::get("app.debug");
}
?>

See Also

add a note

User Contributed Notes

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