What's the difference between these 2?
$dog = new Dog();
Dog :: Dog();
Dog :: Bark(); <-- have to insert a space otherwise will show an icon :D
I don't know when to use which. Thanks for any advice.
09-23-2005, 10:38 PM
09-24-2005, 01:42 AM
I will be honest, the first time I read that I was still confused, however I now use this method alot. A "real world" example might be...
Your class 'NewsletterSystem' has a function called 'CheckEmail' which checks to see if the user entered a valid e-mail address... In another part of your site you need to check for a valid e-mail address, but thats all, you dont need to sign the user up to the newsletter or send it out or anything...
So instead of creating an object and calling the function, you just run:
NewsletterSystem::CheckEmail( ... )
So you dont have to re-write the e-mail checking code into your new script, and you dont have to go to the extent of creating/storing an object.
PHP's PEAR ( http://pear.php.net/ ) use this for error checking.. The main class 'PEAR' has an error handling function, and alot of the extensions reference it from:
PEAR::error_function_name( ... )
as the PEAR object is quite large and when you only need 1 simple function, loading an entire object is quite simply a waste of time.