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 trialIris Avalon
14,477 PointsWhy do we use a static operator for the script method?
I'm a little confused as to why we use a static operator when calling the script method on the HTML class. In the HtmlBuilder.php file, the script method isn't declared as static. Wouldn't we use the -> operator instead of the :: for a method like this?
I don't think I quite grasp the use cases behind each as well as I thought I did.
2 Answers
banned banned
Courses Plus Student 11,243 PointsLaravel is pretty complex, it might be that other classes use it. The classname HtmlBuilder and not HTML.
thomascawthorn
22,986 PointsI believe HTML is a facade for HTMLBuilder.
Take a look at app/config/app.php. Scroll down and after a list of service providers, you'll see a list of aliases. In that list is HTML :-) This means HTML may not be an exact representation of the class name, and instead refers to something else.
Take a look at app/laravel/framework/src/illuminate/Support/Facades/HTML.php
The HTML facade extends Facade so also take a look at app/laravel/framework/src/illuminate/Support/Facades/Facade.php
You can see at the top of the HTML facade class @see HTML builder. I don't quite know about facades, but my guess is that there's a bit of laravel magic going on. Somewhere along the line, your static call is being translated to an instantiated and method call of HTMLBuilder.
If you find out more, come back and tell us!