wppaste
WordPress

WP_HTML_Doctype_Info::__construct( string|null $name, string|null $public_identifier, string|null $system_identifier, bool $force_quirks_flag )

Since
6.7.0
Source
wp-includes/html-api/class-wp-html-doctype-info.php:183
Constructor.

Description

This class should not be instantiated directly.
Use the static self::from_doctype_token method instead.

The arguments to this constructor correspond to the "DOCTYPE token" as defined in the HTML specification.

DOCTYPE tokens have a name, a public identifier, a system identifier, and a force-quirks flag. When a DOCTYPE token is created, its name, public identifier, and system identifier must be marked as missing (which is a distinct state from the empty string), and the force-quirks flag must be set to off (its other state is on).

Compatibility

WordPress
since 6.7.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

$namestring|null
Name of the DOCTYPE.
$public_identifierstring|null
Public identifier of the DOCTYPE.
$system_identifierstring|null
System identifier of the DOCTYPE.
$force_quirks_flagbool
Whether the force-quirks flag is set for the token.

Performance profile

How much work a call to WP_HTML_Doctype_Info::__construct() 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
14–172

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

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

What one call costs · 3 distinct outcomes

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

WhenInstructionsCalls it makes
always14–168none
$name === "html"32–170strtolower()
$name === "html" && $public_identifier !== null && $system_identifier !== null34–172strtolower(), strtolower()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev20414–170752 fewer instructions than PHP 8.5
8.520614–17275
8.420614–17275183 fewer instructions than PHP 8.3
8.338914–35575
8.238914–35575
8.138914–35575
7.438914–35575

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 · 1

Used by · 1

Source code

	private function __construct(		?string $name,		?string $public_identifier,		?string $system_identifier,		bool $force_quirks_flag	) {		$this->name              = $name;		$this->public_identifier = $public_identifier;		$this->system_identifier = $system_identifier; 		/*		 * > If the DOCTYPE token matches one of the conditions in the following list,		 * > then set the Document to quirks mode:		 */ 		/*		 * > The force-quirks flag is set to on.		 */		if ( $force_quirks_flag ) {			$this->indicated_compatibility_mode = 'quirks';			return;		} 		/*		 * Normative documents will contain the literal `<!DOCTYPE html>` with no		 * public or system identifiers; short-circuit to avoid extra parsing.		 */		if ( 'html' === $name && null === $public_identifier && null === $system_identifier ) {			$this->indicated_compatibility_mode = 'no-quirks';			return;		} 		/*		 * > The name is not "html".		 *		 * The tokenizer must report the name in lower case even if provided in		 * the document in upper case; thus no conversion is required here.		 */		if ( 'html' !== $name ) {			$this->indicated_compatibility_mode = 'quirks';			return;		} 		/*		 * Set up some variables to handle the rest of the conditions.		 *		 * > set...the public identifier...to...the empty string if the public identifier was missing.		 * > set...the system identifier...to...the empty string if the system identifier was missing.		 * >		 * > The system identifier and public identifier strings must be compared...		 * > in an ASCII case-insensitive manner.		 */		$public_identifier = null === $public_identifier ? '' : strtolower( $public_identifier );		$system_identifier = null === $system_identifier ? '' : strtolower( $system_identifier ); 		/*		 * > The public identifier is set to…		 */		if (			'-//w3o//dtd w3 html strict 3.0//en//' === $public_identifier ||			'-/w3c/dtd html 4.0 transitional/en' === $public_identifier ||			'html' === $public_identifier		) {			$this->indicated_compatibility_mode = 'quirks';			return;		} 		/*		 * > The system identifier is set to…		 */		if ( 'http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd' === $system_identifier ) {			$this->indicated_compatibility_mode = 'quirks';			return;		} 		/*		 * All of the following conditions depend on matching the public identifier.		 * If the public identifier is empty, none of the following conditions will match.		 */		if ( '' === $public_identifier ) {

Changelog

Introduced in 6.7.0. Unchanged from 6.7.7 through 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.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/html-api/class-wp-html-doctype-info.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.