در حال بارگذاری ...

Introducing Symfony VarDumper0:00

The next component we will review is var_dump. Now, this is a very, very simple one, not a huge amount to tell you here, so this will be a pretty quick video. But you know what? It's already in Laravel behind the scenes, and you probably take it for granted. So let's see what's going on here. Let's go to Sublime Text. I just have a new folder here and an index.php file. So imagine, you know, like a tasks collection, just a quick dummy example here, so that we have something to dump onto the screen. All right, so this will be composed with an array of tasks that we will assign. Okay, let's have a class called Task. And next, this will be composed with, how about just a description? Nothing else. And let's live dangerous and make it public. Okay, cool, right? So your tasks collection should be composed with an array of tasks.

Creating Sample Tasks Array0:44

And let's live dangerous and make it public. Okay, cool, right? So your tasks collection should be composed with an array of tasks. All right, so if we were to set this up, let me give you some more real estate on the screen. A new tasks collection, and each one, like I said, will be a task. So go to the store, and then maybe finish this screencast. And then, how about destroy that guy who keeps spamming the forum with Korean casino links. So this looks good. So if I var_dump it, and we view this in the browser, this is very likely what you're going to get. Very likely, you'll see something like this.

Using Chrome Var-dumpling Extension1:21

So if I var_dump it, and we view this in the browser, this is very likely what you're going to get. Very likely, you'll see something like this. Now, you may know though, from a lot of videos at Laracasts, it doesn't come out this way. And that's because I have this little extension installed. It's a Chrome extension called var-dumpling. So just google that, and you'll have it set up in 30 seconds. Anyways, if I give it a refresh, you can see that it does format your code a little bit more nicely. So even if you don't use that symfony component, you could still reference this, and it'll work anywhere. It's really useful for local stuff. But anyways, I'm going to turn that off and bring it back to what we had before. Now, let's pull in the component. composer require symfony/var-dumper. Okay, and that seems to have worked. So now, all you have to do is change var_dump to dump.

Installing VarDumper via Composer2:02

Now, let's pull in the component. composer require symfony/var-dumper. Okay, and that seems to have worked. So now, all you have to do is change var_dump to dump. But with the code as it is right now, like if we try it out, we're probably going to get an error. Yep, dump does not exist. And that's only because in this case, it's a new project. We haven't even loaded the autoload.php file. And normally, you would do that within like a bootstrap file, or if you use Laravel, it does it for you behind the scenes. So in my case, yeah, we're just going to do it right at the top. So when we require this, it'll set up our autoloader. And now symfony, as part of this package, it has a global function. So if we take a look, let's see if we can find it here.

Enabling Autoload and dump()2:46

And now symphony, as part of this package, it has a global function. So if we take a look, let's see if we can find it here. There we go. So autoload this files list, resources, functions, dump. And there we go. This is the only function you get. So now, rather than using var_dump, you would use dump. Let's try it out. We've already updated this line. So if I come back and give it a refresh, there you go. So now, we have a much easier way to scan the makeup of this object. All right. So just as a recap, var_dump, the normal way, may look like this, or if you install this extension, change it to dump. And yeah, look how much nicer this looks. A lot easier to take in. Okay. So yeah, not too much education going on here. Just a quick review of a package that you may not know about. And like I said, behind the scenes, Laravel makes use of this.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟