Reading PHP Prototypes 07-19-2015, 12:15 AM
#1
What is a PHP Prototype?
A PHP prototype, also known as a function definition, is an example of a PHP function that you will see somewhere in the PHP manuals when you look up a certain function. An example would be something like the date function definition -
string date ( string format [, int timestamp])
Being able to read these shouldn't be that hard, but it requires a little prior knowledge in PHP to have a full understanding.
Example -
Let's use date's prototype as an example.
string date ( string format [, int timestamp])
The first part of a PHP prototype is always at the beginning, and it's the data type that is returned after the function executes successfully. In this case, it's a string, which is a line of characters. However, the data type of what is returned could be many other things such as int, mixed, array, bool, etc.
The next part is obviously the name of the function, which is date.
Functions can take a range of parameters, some can take none at all. The parameters are enclosed in parenthesis after the function name and are separated by a comma. Before the parameter name is the data type that the parameter must be input as.
The date function takes two parameters, which are format and timestamp. The first parameter, format, must be input as a string and we know this because the word string comes before the parameter name. The second parameter, timestamp, must be input as an integer.
There are two differences between the two parameters. The obvious first is that one is a string and one is an integer. The next is that one is optional and the other isn't.
In this case, the timestamp parameter is optional, and we know this because it's enclosed inside brackets.
Outro
Most if not all of these principles can be applied to most of PHP's functions, this is intended to be a reference guide for the future if you don't know or forget how to read PHP prototypes, however for the sake of simplicity I used an easy function. Thanks for reading.
A PHP prototype, also known as a function definition, is an example of a PHP function that you will see somewhere in the PHP manuals when you look up a certain function. An example would be something like the date function definition -
string date ( string format [, int timestamp])
Being able to read these shouldn't be that hard, but it requires a little prior knowledge in PHP to have a full understanding.
Example -
Let's use date's prototype as an example.
string date ( string format [, int timestamp])
The first part of a PHP prototype is always at the beginning, and it's the data type that is returned after the function executes successfully. In this case, it's a string, which is a line of characters. However, the data type of what is returned could be many other things such as int, mixed, array, bool, etc.
The next part is obviously the name of the function, which is date.
Functions can take a range of parameters, some can take none at all. The parameters are enclosed in parenthesis after the function name and are separated by a comma. Before the parameter name is the data type that the parameter must be input as.
The date function takes two parameters, which are format and timestamp. The first parameter, format, must be input as a string and we know this because the word string comes before the parameter name. The second parameter, timestamp, must be input as an integer.
There are two differences between the two parameters. The obvious first is that one is a string and one is an integer. The next is that one is optional and the other isn't.
In this case, the timestamp parameter is optional, and we know this because it's enclosed inside brackets.
Outro
Most if not all of these principles can be applied to most of PHP's functions, this is intended to be a reference guide for the future if you don't know or forget how to read PHP prototypes, however for the sake of simplicity I used an easy function. Thanks for reading.
XMPP - wrath@xmpp.jp




![[+]](https://sinister.li/images/modern/collapse_collapsed.png)











![[Image: 7ajmN5P.jpg]](https://i.imgur.com/7ajmN5P.jpg)













