Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2003
    Location
    Singapore
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Difference in :: and new

    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

    I don't know when to use which. Thanks for any advice.

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #3
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Regular Coder
    Join Date
    Jul 2003
    Location
    Singapore
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok thanks very much.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •