php8.5
Home/ Manual/ yaconf / yaconf/ Yaconf::has

Yaconf::has

PHP function Edit on GitHub ✎

(PECL yaconf >= 1.0.0)

Check whether a configuration value exists

Description

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.

Yaconf::has example

php
<?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

  • Yaconf::get
  • Yaconf::__debug_info

Source: reference/yaconf/yaconf/has.xml · from the official PHP manual (php/doc-en)