Login Register






Tutorial Reading PHP Prototypes filter_list
Author
Message
Reading PHP Prototypes #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.
XMPP - wrath@xmpp.jp

[+] 1 user Likes Crypt's post
Reply

RE: Reading PHP Prototypes #2
Really basic thing, but something that confused me when I was first starting out on plugins. Since documentation on PHP is plentiful, this is good to know.
[Image: 7ajmN5P.jpg]

Telegram: Oni_SL (Link)

Reply

RE: Reading PHP Prototypes #3
Something so simple but often overlooked. Nice guide.

Reply

RE: Reading PHP Prototypes #4
(07-19-2015, 12:33 AM)Oni Wrote: Really basic thing, but something that confused me when I was first starting out on plugins. Since documentation on PHP is plentiful, this is good to know.

(07-19-2015, 12:33 AM)Eclipse Wrote: Something so simple but often overlooked. Nice guide.

Thanks, glad you guys liked it. I plan on making more tutorials like these on essential stuff that people should know.
XMPP - wrath@xmpp.jp

Reply