Difference between Fwrite and Fputs?


I am currently programming a small practice in which several partners are the fputs and the fwrite in which does not seem to affect the operation of the practice (which I am using fwrite, was the first I used), and I entered the doubt of the differences of these. It would be very helpful if they explained to me. Thanks

asked by Cesar Reyna 11.10.2018 в 01:57

1 answer


If you check fputs in the PHP Manual , you'll get Note that it is an alias of fwrite . Which means that it's actually the same function:


fputs - Alias of fwrite()




This function is an alias of: fwrite() .

PHP has several similar cases, as explained in the section List of functions alias :


There are a few functions in PHP that can be called with more than one   first name. In some of the cases there is no preferred name of   Among the multiple names, is_int() e is_integer() are a good   example. However, there are functions that changed their name because of   a clean API or some other reason and the old names only   are preserved as aliases to maintain compatibility with versions   previous It is usually a bad idea to use this type of alias, as they can   become obsolete or change their name, and make it impossible to   portability of the script. This list is provided to help the   people who want to update their old code to a new one   syntax.

We must look for the reason why fputs is an alias, to know if it is necessary to avoid its use.

Let's see:

When it says Base Syntax , it means that you can use either, because the alias reason is not due to saving compatibility with other libraries. Anyway, an alias will always be an alias. I would always use the original.

answered by 11.10.2018 / 11:52