Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Building Websites with PHP Contact Form & Sending Email Installing SwiftMailer

Gareth Redfern
Gareth Redfern
36,217 Points

Name Spacing For Swiftmailer

When you create the transport object on line 43 the following is used:

$transport = Swift_SendmailTransport::newInstance();

My question is how does the app know how to find that static method in particular as its not namespaced. Should it not be prefixed with a \?

Great question. Wouldn't have even thought to have asked it.

1 Answer

Hi Gareth Redfern

Take a look at this file SmtpTransport.php

On Line 53 there is the method that the class you mentioned inherits from.

This method calls the 'new' keyword for you. This is not the ideal way IMHO, but it works.

Oziel Perez
Oziel Perez
61,321 Points

Do you have any idea what approach were they going with to instantiate a class object in this way? It seems a bit overengineered but then again, not sure if I'm there's something I'm not aware of that makes them write the code like that.