WooCommerce Code Reference

Warning
in package

Encapsulates warnings produced by the library.

Warnings can be suppressed (individually or all) if required. Also, it is possible to override warning handler (which is trigger_error() by default).

Tags
phpstan-type

WarningHandler callable(string $errorMessage, int $warningId, ?int $messageLevel): void

Table of Contents

ALL  = 63
NONE  = 0
WARNING_ASSIGN  = 2
WARNING_CONFIG  = 4
WARNING_CONFIG_DEPRECATION  = 16
WARNING_FULL_SCHEMA_SCAN  = 8
WARNING_NOT_A_TYPE  = 32
$enableWarnings  : int
$warned  : array<string|int, mixed>
$warningHandler  : callable|null
enable()  : void
Re-enable previously suppressed warning by id (has no effect when custom warning handler is set).
setWarningHandler()  : void
Sets warning handler which can intercept all system warnings.
suppress()  : void
Suppress warning by id (has no effect when custom warning handler is set).
warn()  : void
warnOnce()  : void

Constants

Properties

Methods

enable()

Re-enable previously suppressed warning by id (has no effect when custom warning handler is set).

public static enable([bool|int $enable = true ]) : void
Parameters
$enable : bool|int = true
Tags
example

Warning::suppress(Warning::WARNING_NOT_A_TYPE) re-enables a specific warning

example

Warning::suppress(true) re-enables all warnings

example

Warning::suppress(false) suppresses all warnings

Return values
void

setWarningHandler()

Sets warning handler which can intercept all system warnings.

public static setWarningHandler([callable|null $warningHandler = null ]) : void

When not set, trigger_error() is used to notify about warnings.

Parameters
$warningHandler : callable|null = null
Tags
phpstan-param

WarningHandler|null $warningHandler

Return values
void

suppress()

Suppress warning by id (has no effect when custom warning handler is set).

public static suppress([bool|int $suppress = true ]) : void
Parameters
$suppress : bool|int = true
Tags
example

Warning::suppress(Warning::WARNING_NOT_A_TYPE) suppress a specific warning

example

Warning::suppress(true) suppresses all warnings

example

Warning::suppress(false) enables all warnings

Return values
void

warn()

public static warn(string $errorMessage, int $warningId[, int|null $messageLevel = null ]) : void
Parameters
$errorMessage : string
$warningId : int
$messageLevel : int|null = null
Return values
void

warnOnce()

public static warnOnce(string $errorMessage, int $warningId[, int|null $messageLevel = null ]) : void
Parameters
$errorMessage : string
$warningId : int
$messageLevel : int|null = null
Return values
void