...

View Full Version : Difference in :: and new



qazs
09-23-2005, 04:47 PM
Hi,
What's the difference between these 2?
Example 1:
$dog = new Dog();
$dog->Bark();

Example 2:
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.

marek_mar
09-23-2005, 09:38 PM
http://www.php.net/manual/en/keyword.paamayim-nekudotayim.php

missing-score
09-24-2005, 12: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.

qazs
09-24-2005, 07:54 AM
Ok thanks very much.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum