PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
class stringHandler{
public function __construct()
{
}
public function stringIsAlphaNumeric($string)
{
if (strspn($string,'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') == strlen($string))
{
return true;
}
else
{
return false;
}
}
}
You asked if you'd gain anything. My opinion is that you won't. You might as well use namespaces or separate files to group functions if that's all you're after. Object oriented programming can definitely improve the structure of your code, but only if applied in a relevant manner, not blindly "objectifying" everything. You should read on basic concepts such as abstraction, polymorphism, inheritance, decoupling and the various design patterns that implement those concepts to real-world scenarios.
Classes can be a really useful tool, and it's good you are excited about them. Just use that excitement to learn to use them properly. Don't worry about using them improperly though. That's how you will learn. When you use classes improperly it quickly becomes obvious that something isn't right and then you can do something called "refactoring". Refactor enough times and you will have a nice little design