[0:00] so occasionally I do get comments [0:02] discussing whether or not object or into [0:03] PHP is better than procedural PHP and [0:06] this is something I will get because I [0:07] do have a optic oriented PHP cores and I [0:10] do also have some project videos where I [0:12] have a object-oriented version and I [0:14] have a procedural version and sometimes [0:16] I get people jumping into one of those [0:18] project videos not really to watch the [0:19] video but to let everyone know that you [0:21] should not learn after you go into PHP [0:23] so figured why not do a short video just [0:25] kind of going over what exactly are some [0:27] of the benefits and you know we call [0:30] those pros and cons when it comes to [0:31] learning object-oriented PHP versus [0:33] learning procedural PHP what exactly is [0:35] the difference between procedural and [0:37] object under PHP and is it something you [0:39] should learn you know what are the pros [0:41] and cons to learning each of these [0:42] different styles of coding and of course [0:44] there's going to be a lot of people [0:45] watching this video who do already have [0:47] a lot of years of experience when it [0:48] comes to optic oriented versus [0:50] procedural and just knowing the [0:51] differences but there's also a lot of [0:53] new people watching so I figured why not [0:55] just do one for them you know so they [0:57] know a little bit about okay so there's [0:59] something called procedural there's [1:00] something called object oriented and [1:02] should you listen to people who tell you [1:04] not to learn object oriented like what [1:05] exactly is that all about so the first [1:07] thing I want to point out here is well [1:10] point out I can actually show you [1:12] because I set up this very basic example [1:14] here but as you can see inside my code [1:17] editor here my my visual studio code I [1:19] have a example of using procedural PHP [1:21] and I do also have an example using [1:23] object-oriented PHP and these are very [1:25] very bone examples okay again it's just [1:28] an example to kind of prove a point here [1:29] so the code inside my editor is not [1:31] going to make any sort of sense it's not [1:33] going to do anything it's just so that [1:35] beginners can see the difference when it [1:36] comes to the visuals of how procedural [1:38] looks like when it comes to object [1:40] oriented okay so inside my editor here I [1:43] do have an example of procedural [1:45] programming and again this is going to [1:46] carry over into JavaScript if you're [1:48] interested in JavaScript so again it's [1:50] just basically procedural versus object [1:52] oriented it doesn't really matter with [1:54] the language itself so inside my editor [1:56] I have a index page and inside my [1:58] website I would like for a person to go [2:00] in and be able to type in something [2:02] inside this particular input here in [2:04] this case it's just a username and a [2:05] password and that basically means when [2:07] they type it in they're going to send [2:09] this information to another page inside [2:11] our website in this case here I'm [2:13] sending it to a [2:14] formhandler.ink.php and if I were to [2:16] take a look at that page you can [2:17] actually see when it comes to procedural [2:19] PHP again PHP in this example here if I [2:22] were to go in here you can see that we [2:24] basically just go in we check for a [2:26] request method to make sure that this [2:27] was submitted by a form then we go down [2:30] we grab the data and then we actually do [2:32] something with it in this case if you [2:34] authenticate the user by doing a [2:36] authentication function that we have [2:38] somewhere inside our code and that code [2:40] could for example be inside a file [2:43] called login.link.php which basically [2:45] just have a basic function that goes in [2:48] and does some sort of authentication [2:49] again the code doesn't make any sort of [2:51] sense but just to kind of show how we [2:53] split up the tasks inside our code into [2:56] different functions maybe inside a [2:58] separate page so that we don't have to [3:00] to rewrite code all the time and we can [3:02] reuse our code and it's just a much [3:04] better solution so that's why we use [3:06] functions inside our code again this is [3:08] very basic programming this is something [3:10] you'll learn almost immediately in any [3:12] sort of course so the basic idea here is [3:14] that you have this one file that takes [3:16] care of the actual request from the user [3:18] in this case you're logging in into the [3:20] website and then you just have a [3:22] separate file that has a bunch of [3:23] functions that might be related to a [3:25] login system so that is how you would do [3:28] that but when it comes to optic oriented [3:30] PHP you would do it slightly different [3:32] so if I were to go inside my object or [3:34] insert example here and go inside my [3:36] formhandler.ink.php you're going to see [3:38] that it looks a little bit different we [3:40] do still go inside and check is this [3:42] actually accessed by posting the login [3:45] form and if so then we go in and grab [3:47] the data but then we also go in and we [3:49] want to include a file which is going to [3:51] be a class file so in this case you're [3:53] not a file that is full of functions but [3:55] a class that has login specific [3:57] properties and methods so people who's [4:00] never done object oriented before [4:02] properties and methods are kind of the [4:04] same thing as a variable and functions [4:07] but not quite but just to give a very [4:09] what should you say like comparative [4:11] thing to make people understand what [4:13] exactly it is that is what we're going [4:14] to pretend it is and this particular [4:16] class file is going to look something [4:17] like this so we go inside a another file [4:20] and instead of having a bunch of [4:22] functions we actually have a class which [4:24] is going to encapsulate a bunch of [4:26] properties and methods that has a [4:29] specific purpose so in this case here we [4:30] have a property or we have two [4:32] properties actually these are called [4:34] Fields if you have to be very specific [4:36] here then we go in and we actually say [4:38] we want to assign some data to these [4:40] fields so when we actually call upon [4:42] this class here and create a object [4:44] based off of this class or this [4:46] blueprint we have here then we can [4:48] assign data to the object by passing in [4:50] data into the class when we actually [4:53] instantiate it and then we have a method [4:55] inside the class itself that is kind of [4:57] like a function again just to use some [4:58] comparative words for people who's never [5:00] done it before to understand what this [5:01] is this is kind of like a function where [5:03] you go and then you just do the [5:05] validation and authentication like you [5:07] would inside that other function inside [5:09] the previous example so what you then do [5:11] inside the form Handler when you call [5:12] upon this file is to create a object [5:15] based off the class because a class is a [5:17] blueprint where we can create a object [5:20] that has all the information that is [5:21] inside this class but the object is [5:24] going to change depending on what we [5:25] pass into the class when we actually [5:27] instantiate this class here this is not [5:29] supposed to turn into a tutorial annual [5:31] okay we're not we're not supposed to [5:33] teach about classes in this video but [5:35] just to give an idea about how it is [5:37] different so basically instead of having [5:39] just a bunch of functions inside a file [5:41] where the file is named according to [5:44] what the functions are supposed to do so [5:46] all of a sudden we have all these [5:47] different files with different functions [5:49] in it we instead create a class file [5:51] that has properties and methods inside [5:53] of it that has basic information about [5:55] this particular feature you might have [5:57] inside your website so you can have a [6:00] you can have a class here in this case [6:02] we could call you so we could also call [6:04] it login so it's more specific to the [6:06] login system where you just basically go [6:08] and you have all this information like [6:09] typically would with functions as well [6:11] inside this class here but now using [6:14] classes is also going to give you a [6:16] bunch of different good things about it [6:18] for example that you encapsulate all the [6:20] different you know features that you [6:22] have inside all the different code into [6:24] different classes that can then extend [6:26] to each other in order to only be able [6:27] to access certain classes if it comes [6:29] from another class which means that we [6:31] can take more sensitive code and put it [6:34] inside a sensitive class that should [6:36] only be accessible to certain other [6:38] classes and in disorder sense when we [6:40] have very sensitive code we can make [6:42] sure it only gets run under certain [6:44] conditions where some classes can access [6:46] it so like there's a bunch of things [6:48] here when it comes to classes and I can [6:50] talk about this forever but there's a [6:51] lot of benefits to using optic or into [6:53] PHP versus procedural PHP so why do [6:57] people not like object oriented PHP [6:59] versus procedural why do some people [7:01] fight so heavily for doing procedural [7:04] PHP inside a website I think the first [7:07] thing that needs to be pointed out here [7:08] is that the mindset of having procedural [7:11] PHP being better than Arctic down to PHP [7:13] or object or into PHP being better than [7:15] procedural PHP is kind of a wrong [7:18] mindset to have I can completely [7:20] understand that some people they have a [7:22] preference to watch one or the other but [7:23] it is also important to keep in mind [7:25] that these are just tools that are used [7:26] in order to do something inside your [7:28] application in this case here a website [7:31] so in some cases where you might have a [7:33] certain website that only needs one [7:35] little feature using PHP for example [7:37] just a contact form you know of course [7:39] you wouldn't be using object or into PHP [7:41] in order to do that because it is just a [7:43] contact form there's no extensive [7:45] features that are planned in the future [7:47] so there's not really any reason to over [7:49] complicate the code and that's really [7:50] one of the key points that I also have [7:52] to talk about when it comes to optic [7:54] oriented PHP because yes object oriented [7:57] PHP is much more complex than just doing [7:59] procedural for the beginners watching [8:01] this video essentially what procedural [8:03] is is when you have a place inside one [8:06] of the pages inside your website where [8:07] you need a certain piece of code then [8:09] you go into that place inside the page [8:12] for example inside this index page here [8:14] let's say I need to add a contact form [8:15] at the bottom here I would just go in [8:17] create my PHP tags and I'll just start [8:19] creating all the code for my contact [8:21] form that is a procedural PHP mindset [8:24] but when it comes to object oriented PHP [8:26] we all of a sudden take this code and we [8:29] split it apart and we encapsulate it [8:31] into different files and different [8:32] classes and all of a sudden we have many [8:34] different codes spread out all over the [8:37] place which is going to make things a [8:39] little bit more organized and scalable [8:40] when it comes to larger applications but [8:43] when it comes to just a small feature [8:44] like for example a contact form yes you [8:47] should most likely not over complicate [8:48] things by spreading everything out into [8:50] different classes so there is no such [8:52] thing as procedural PHP or Optic or into [8:55] PHP being better than the other you have [8:57] to look at the specific application [8:58] you're sitting with and from that you [9:00] can determine is one of them going to be [9:02] better because yes for example when it [9:03] comes to a login system I think [9:05] personally we're moving into a area [9:07] where it gets a little bit more complex [9:09] with the PHP application what we need to [9:11] make sure that we can actually scale [9:13] things properly and have everything [9:14] organized when it comes to the code so [9:16] in those sort of situations I do not [9:18] think that procedural PHP is going to be [9:20] a benefit because now we're moving into [9:22] a more complex PHP application for your [9:25] website in order for more advanced [9:28] features when it comes to using a [9:30] back-end language inside your website [9:32] and yes there is pros and cons when it [9:34] comes to using both procedural and [9:36] object-oriented php's I can for example [9:37] give you a small list here of things [9:39] that is pros and cons to both of them so [9:41] again it really depends on the [9:44] application you're sitting with and you [9:45] have to determine which one is going to [9:47] be better for your particular project [9:48] for example if you have a certain [9:51] application that is going to have a lot [9:52] of performance critical applications [9:54] inside of them then you may consider [9:56] some aspects of your application being [9:57] procedural Sims object oriented is it [10:00] slightly more complex when it comes to [10:02] Performance so again there is pros and [10:04] cons for both different types and you [10:06] have to look at the individual thing or [10:08] the the thing the application you're [10:10] sitting with and of course that is not [10:11] going to stop people from just being [10:13] heavily biased when it comes to for [10:14] example being against or for object [10:16] oriented PHP people will still come [10:18] inside some videos or maybe underneath [10:20] this video here heavily arguing for why [10:23] object oriented PHP is just complete [10:25] garbage or why procedural PHP should [10:27] never be used and this opinion can come [10:29] from many different reasons for example [10:30] some people just think the learning [10:32] curve to learn object or into PHP is too [10:34] big and they don't want to get into it [10:35] because it's very complex which is going [10:37] to lead to some biased opinions when it [10:39] comes to you know arguing against optic [10:41] oriented PHP we do also have people who [10:44] just thinks that it is much more complex [10:46] when it comes to optic oriented PHP [10:48] because the code all of a sudden gets a [10:50] little bit more less hard to read if [10:51] you're not careful about it you need to [10:53] make sure you organize things properly [10:54] inside object or into PHP to make sure [10:56] the classes make sense and there's [10:58] comments explaining what exactly things [11:00] do because when you start taking apart [11:02] code and splitting it out into different [11:03] files and different classes you need to [11:06] make sure that there is a system going [11:08] so people can actually look look at [11:09] these and understand where the code is [11:11] and to some people this organization [11:13] here or the mindset of splitting things [11:15] into different files instead of just [11:16] having everything in one place is going [11:18] to be something to have a hard time [11:20] grasping because if you have to be [11:22] honest here I can see where that opinion [11:23] is coming from I can definitely see how [11:26] a certain mindset where you say okay [11:28] well I need a contact form right here so [11:30] therefore this is the place inside my [11:32] website inside that particular file that [11:35] I'm going to put my PHP code for that [11:37] particular application so all of a [11:39] sudden when you start splitting code [11:40] into different files all of a sudden [11:41] you're going away from this very simple [11:43] mindset of this is where the code needs [11:45] to be so therefore this is where it is [11:47] going to be inside my file to okay so [11:49] now we have a file for contacting the [11:52] database and we have a file for [11:54] performing actions when the user submits [11:56] data and then we have another file [11:58] that's showing something inside the [11:59] website all of a sudden we have all [12:01] these tasks split out and that can be a [12:03] hard thing to grasp especially as a [12:05] beginner some people are also going to [12:07] give more geeky [12:09] key [12:10] technical concerns about object-oriented [12:13] PHP which could for example be [12:15] performance because yes optic run to PHP [12:18] is slightly more performance heavy when [12:20] it comes to the code because there's a [12:22] encapsulation and you have to [12:24] instantiate classes and that kind of [12:25] thing so again the important Point here [12:28] that I'm trying to make is there's no [12:30] such thing as one of them being better [12:32] than the other it is much about what [12:34] exactly are trying to build inside this [12:35] website here and do you actually plan [12:37] for this to be more scalable in the [12:39] future do you plan to add more features [12:41] to this website because if you do then [12:44] maybe you should start out with object [12:46] oriented PHP so you do have a [12:49] foundational system that you can [12:50] actually build upon in a much more [12:53] practical sense so again just a small [12:55] rant here to give my personal take on [12:57] this because I do know that a lot of [12:58] people have a very strong opinion about [13:00] one or the other and I do see a lot of [13:02] these opinions a lot inside my videos [13:04] which by the way small advertisement [13:06] here I do have a object oriented PHP [13:08] course and I do also have a procedural [13:10] PHP course which I just updated so if [13:13] you're interested in learning PHP I do [13:15] have different [13:16] what is it called playlist that you can [13:19] watch so we do have something inside [13:20] this channel here that is going to be [13:21] very beneficial for people so with that [13:23] said I hope you all enjoyed this video [13:25] here and I'll see you guys next time [13:31] foreign [13:34] [Music]