defined - chung-leong/qb GitHub Wiki

defined - Checks whether a given named constant exists

bool defined(string $name)

defined() is always evaluated at compile-time. It can be used to exclude code sections from the compilation process.

<?php

/**
 * @engine qb
 * @param float64 $a
 * @local float64 $b
 * @return float64
 */
function test($a) {
	$b = $a * $a;
	if(defined("DEBUG")) {
		echo "Returning $b\n";
	}
	return $b;
}

?>

In the example above, the QB compiler will either include or exclude the line inside the if statement, depending on whether DEBUG is defined. No branch instruction will be generated in either case.

Version

1.0 and above.