I’m wrapping my inferior mind around classes. It is struggling with it by looking at other peoples code and finding it hard to see how it relates to my own code. I am hoping you can help me see how it works by turning 2 simple functions I have into classes so that I can see a relatable example.
A simple couple of functions:
function make_url_friendly($string) {
$remove = array(',',' ','?','=','&','-','|');
$replace = array('_','_','_','_','','_','');
$string = strtolower(str_replace($remove,$replace,$string));
return $string;
}
function save_page($url) {
$sql = 'INSERT INTO pages
SET url="' . mysql_real_escape_string(make_url_friendly($url)) . '" ';
mysql_query($sql);
}
save_page('/questions/ask');
What might be the oop equivalent to functions like this?
Edit:
As Shef pointed out in the comments, you really want to group items of similar function into their own class. For example, all your function s which do something to the DB would have a class different than your functions which handle form error checking.
Therefore in your example
make_url_friendlywould be in a different class fromsave_page