php sample terms?



I am a newbie, I've been reading some samples, looking for the definition of the sample abreviations, here is an example:

int readfile(string filename, int [use_include_path]);

I understand the "readfile()" function, but do you know what "int", "use_include_path", or "string filename" means, Im just trying to understand how to read this line? if anyone has any data, please help! Thanks in advance!! Frodo
The bit of text you posted is referred to as the function's "prototype". It's essentially just a definition of what input ("arguments") the function takes and what it outputs ("return"). The readfile() prototype from the manual is a bit different from what you posted -- where'd you get it? Anyway, the official one is a bit clearer:

int readfile ( string filename [, bool use_include_path [, resource context]])

This is in fact a great example (and a good question, by the way).

(After typing all of the below I realized that the PHP manual has a page about how to read these things. Oops.)

Okay, The first word is "int". It comes before the name of the function, which means that it's the "return type", that is, it's the type of data that you will get back when you run the function. To programmers, "int" always means "integer" (that is, a whole number, e.g. -1, 0, 1, 2, 3, ...). So what integer does it return, exactly? Well, just below the prototype in the manual it says "Returns the number of bytes read from the file."

After that is the name of the function followed by the argument list. This is the list of different kinds of data that you can feed to the function, and in what order. The first argument says "string filename". A string is just a bit of text; in this case, the function expects that text to be the name/path of the file that you want to read.

After that we see a couple more possible arguments, but these are enclosed in square brackets. That means that they're optional. The word "bool" stands for "boolean", which is a value that's either true or false. In this case, it's followed by "use_include_path". So if you want to be able to read files from the include path (read the documentation for more information about this), then you would put "true". If you don't want to, then you could put "false", or, since it's optional, just leave it out.

The last argument is a "resource", which is a generic name for a special kind of data (for example, when you connect to a mysql server, PHP stores that connection as a "resource"). I won't go into what a "context" resource is, since you don't really need to know it right now.

A word of caution, though: In PHP, you can't just skip arguments. For example, if a function's second and third arguments are both optional, you can't skip the second and not the third. If you want to pass the third argument, you have to pass all of the ones before it as well. So in the above, you wouldn't be able to specify a context resource without first specifying the use_include_path. If that makes sense.

As for all of the types of data you'll encounter (in addition to int, string, bool, and resource), the manual has a page for that too.