PHP-X itself is developed based on C++11 and uses cmake for compilation and configuration. The following article mainly introduces you to the relevant information about the use of built-in functions in the PHP-X series of tutorials. The article introduces it in great detail through sample code. Friends in need can refer to it. Let’s take a look together.
Preface
This article mainly introduces you to the use of PHP-X built-in functions, which are often used in PHP extension development. Built-in functions, wrappers in PHP-X, make calling these functions as easy as PHP code.
Friends who are not familiar with php-x can read this article: https://segmentfault.com/a/1190000011111074
echo
If you need to output some content in the extension, you can use the echo function. The use of echo is exactly the same as printf in C language. Please refer to printf related articles for details.
In the command line environment (cli), echo will print the screen
In php-fpm or apache, echo will output the content to the browser Server client
PHPX_FUNCTION(cpp_test) { echo("a=%d, b=%f, c=%s.\n", args[0].toInt(), args[1].toFloat(), args[2].toCString()); }
var_dump
Develop and debug PHP When programming, we often need to print the values of some variables. PHP provides the var_dump function to print variables. You can also use var_dump in PHP-X. This function accepts a Variant object.
PHPX_FUNCTION(cpp_test) { var_dump(args[0]); }
include
Include PHP files. Note: If the file does not exist, a fatal error will be thrown. Once loaded correctly, the code in this PHP file will be executed. You can use include to introduce classes and functions implemented by PHP code into extensions.
PHPX_FUNCTION(cpp_test) { include("/data/php/library/Autoloader.php"); }
error
PHPX_FUNCTION(cpp_test) { error(E_ERROR, "error: a=%d, b=%f, c=%s.\n", args[0].toInt(), args[1].toFloat(), args[2].toCString()); }
constant
PHPX_FUNCTION(cpp_test) { auto a = constant("PHP_VERSION"); auto b = constant("PDO::VERSION"); }
global
PHPX_FUNCTION(cpp_test) { //相当于 $_GET auto a = global("_GET"); //相当于 global $config auto b = global("config"); }
Summary
The above is the detailed content of Detailed explanation of examples of built-in functions in the php-X series. For more information, please follow other related articles on the PHP Chinese website!