A great way to organize your tons of functions you will most likely have on your website is by using classes. Classes can be used to hold many functions that you group together – usually by their purpose on the website.
For example, you would probably have functions for executing sql queries in a class of something like “sql”.
Here is how a class is shown in PHP:
[code lang=”php”]
[/code]
A class is created with “class” then space, the name of the class, and brackets (opening and closing).
Let’s say you created this class and you want to execute a function out of this class in your php page. To start a class on your page you have to give the class a variable, like so:
[code lang=”php”]
$sql = new sql();
// Execute function.
$sql->doSql(“SELECT * FROM tbl WHERE id = ‘5’”);
[/code]
This will set $sql as the variable for class “sql”. Executing the functions in a class are just the variable plus the arrow and the function.
No comment yet, add your voice below!