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 Laravel 4 Basics Continuing CRUD Updating Data

Laravel 4.2: Why sometimes array takes () and other times [] and also blade syntax sometimes {{{}}} and other times {{}}

Everything is in the title. This changes are confuse. Thanks

3 Answers

I don't think we've covered blade syntax yet - let me just jump in on that. {{{ 3 curly braces }}} will escape the output. It may run other functions too.. but it certainly uses the built in php function htmlspecialchars(). You can test this by putting a variable that contains html output inside {{{ }}} and you will see the full html element echoed to the screen i.e.

<h1>Heading</h1>

instead of

Heading

{{ 2 curly braces }} is a simple PHP echo without any escaping.

If you display any output created by a user - you will need to escape it to create a safe application. An example of this would be re-filling form inputs with values from a previously submitted form. This stops the user from filling everything out again but opens you up to mean attacks

Hope this helps,

Tom

Casey Clayton
Casey Clayton
16,708 Points

We should however note that in Laravel 5.0 that this has changed! It is now {{ 2 curly braces }} to escape any characters, the triple curly brackets is no longer needed, and now {!! !!} is used when you don't want to escape these characters.

That's true! I'll update this question to specify Larave 4.2.

Right now, Laravel 5.0 has backwards compatability for {{{ }}} (so they wil stilll work as expected) but I suspect this will be phased out pretty soon.

Chema Castellanos
Chema Castellanos
3,984 Points

OK look:

When there are many ways to declare an array:

$myarray = array(); this will set an empty array

$myarray = array("bear", "dog", "horse"); this will set a 3 element array with numerical keys 0, 1, and 2

$myarray = array( "color" => "blue" "animal" => "dog" ); this will set an array of 2 elements with this specific keys

$myarray = [ "color" => "blue" "animal" => "dog" ]; this will set the same but notice that you don't have to declare the word array

$myarray['name'] = "peter"; this will create a new array of 1 elemement with that specific key or add this element to an array if it already exists

thanks, i got it. When you put the key mord array you can write with () and without array with [] since php5.

Thanks