Standard functions in PHP extension function call extensions

Source: Internet
Author: User

These days in the PHP extension function, in the online learning steps and so on, the general problem can also be found, so no longer this wordy, writing this blog because of a problem, Baidu Google did not find, for beginners, this may be useful, for those who have, I think they must have met, So think about it or write it out.problem: In PHP extension want to call C already written things, but do not know how to call, here want to call is standard functionFirst include the header file of the standard library to be called, such as: #include "ext/standard/php_rand.h" to load the header file of a random number we can only invoke the PHPAPI function declared by the php_rand.h header file, such as Php_ These functions are declared in Rand.h: Phpapi void Php_srand (long seed tsrmls_dc); Phpapi long Php_rand (tsrmls_d); Phpapi void Php_mt_srand (Php_uint32 seed tsrmls_dc); Phpapi php_uint32 Php_mt_rand (tsrmls_d); The specific code of these functions can be found in rand.c, calling the parameters of these standard functions can also be known, if it is unclear, what the parameters represent, there is a way to see how the other function is called, and then follow the argument on the line.    such as: I want to call the Php_rand function, but I do not know what it means, in RAND.C to search for the function called it, you can find the following code snippet: Php_function (rand) {long min;    Long Max;    Long number;     int argc = Zend_num_args ();     if (argc! = 0 && zend_parse_parameters (argc tsrmls_cc, "ll", &min, &max) = = FAILURE) return; Number = Php_rand (Tsrmls_c);//This is an example of a call that is modeled after thisif (argc = = 2) {rand_range (number, Min, Max, Php_rand_max); } return_long (number);} Tsrmls_c is a thread-safe, and can be used directly, so use it when you follow that pass. If the parameter is something else, you will find the source of the parameter, search in the source file or the parameter is a PHP call, the time to pass, in short, you can find the meaning of the parameter, you can use it. Then in your extension code. C file # include "Ext/standard/php_rand.h" code in the normal calling function: int number = Php_rand (Tsrmls_c); The number returned is the result you want.

Standard functions in PHP extension function call extensions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.