Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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.