Providing libraries for developers.
Posted: Sun Jan 18, 2009 9:35 am
I have come to a point in my project where I have lots of libraries that other developers can use to create plugins easily. These libraries are only loaded when they are needed (with __autoload).
An example library:
Now it's easy for a plugin developer to use my libraries, he could just do:
The libraries are easy to use and greatly improve the development time. Also, when I take the move in the future and support only PHP 5.3/6, then I can easily move into using namespaces 
Also I'm using exceptions in these library functions like:
Not exactly what I do, but you got the point. 
I'm just wondering am I doing something "wrong"?
Let's say that you pass a string into a built-in PHP function that takes only integers, it will inform you what you did wrong so shouldn't I do that too in my functions? And when something else goes wrong like fopen within the function then return false and log the error (and display it if the DEBUG mode for the script is enabled - in development stage).
Am I being utterly inane or does this make sense to you?
When I code in C# I use exceptions to exit from fatal problems and that makes me think if my approach here is rational.
An example library:
Code: Select all
class string
{
public static function str_replace_count(...) {...}
}Code: Select all
string::str_replace_count('search','replace',$subject,$count);Code: Select all
namespace string;
function str_replace_count(...) {...}
Code: Select all
if (!is_integer($count))
throw new exception('You must pass an integer you dummy');I'm just wondering am I doing something "wrong"?
Let's say that you pass a string into a built-in PHP function that takes only integers, it will inform you what you did wrong so shouldn't I do that too in my functions? And when something else goes wrong like fopen within the function then return false and log the error (and display it if the DEBUG mode for the script is enabled - in development stage).
Am I being utterly inane or does this make sense to you?
When I code in C# I use exceptions to exit from fatal problems and that makes me think if my approach here is rational.