调用函数(Calling Functions)¶
如上所述,PHP 已经有帮我们做了很多事情,C 的扩展并不意味着我们要重新发明轮子。我们也要尽量避免使用 C 非常底层的特性。使用 PHP 函数帮助我们实现和 PHP 编程中类似的行为,这样我们就可以避免可能出现的错误。
The following code opens a file in C and write something on it. Its functionality is limited because it only works onlocal files:
- Although both codes perform the same task, the former is more powerful as it could open a PHP stream, a file in a URL
- or a local file. We can also write the same code using the PHP API, without losing functionality. However, theabove code is more familiar if we are primarily PHP developers.
The same code in PHP: