wppaste
WordPress

wpdb::bail( string $message, string $error_code = '500' ): void|false

Since
1.5.0
Source
wp-includes/class-wpdb.php:3931
Wraps errors in a nice header and footer and dies.

Description

Will not die if wpdb::$show_errors is false.

Compatibility

WordPress
since 1.5.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$messagestring
The error message.
$error_codestringoptional
A computer-readable string to identify the error.
Default '500'.Default: '500'

Return value

void|false
Void if the showing of errors is enabled, false if disabled.

Performance profile

How much work a call to wpdb::bail() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
9–24

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 42.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
3

3 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()one call below wpdb::bail()

Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 4 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wpdb::bail() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always9–13none
!($value instanceof) && !mysqli_connect_errno()16–20mysqli_connect_errno(), wp_die()
!($value instanceof) && mysqli_connect_errno()19–23mysqli_connect_errno(), mysqli_connect_error(), wp_die()
$value instanceof20–24mysqli_error(), wp_die()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev429–245
8.5429–245
8.4429–2453 fewer instructions than PHP 8.3
8.34512–245
8.24512–245
8.14512–245
7.44512–245

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 2

Used by · 3

Source code

	public function bail( $message, $error_code = '500' ) {		if ( $this->show_errors ) {			$error = ''; 			if ( $this->dbh instanceof mysqli ) {				$error = mysqli_error( $this->dbh );			} elseif ( mysqli_connect_errno() ) {				$error = mysqli_connect_error();			} 			if ( $error ) {				$message = '<p><code>' . $error . "</code></p>\n" . $message;			} 			wp_die( $message );		} else {			if ( class_exists( 'WP_Error', false ) ) {				$this->error = new WP_Error( $error_code, $message );			} else {				$this->error = $message;			} 			return false;		}	}

Changelog

Introduced in 1.5.0. One change between 6.7.7 and 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

7.1.0
Return type changed from void|false to false.verified against source
1.5.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/class-wpdb.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.