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