PHP Doesn't Suck Anymore? | Prime Reacts

00:25:42
https://www.youtube.com/watch?v=WsnHWxO7Krw

الملخص

TLDRThe video discusses the evolution of PHP since 2012, showcasing various enhancements that make it a more modern and efficient programming language. The presenter shares personal experiences with PHP, reflecting on the frustrations and newfound excitement associated with its newer features such as traits, array destructuring, null coalescing operators, and type safety. A humorous narrative engages viewers while emphasizing that PHP is far from 'dead' and is indeed a powerful tool in today's programming landscape.

الوجبات الجاهزة

  • 🚀 PHP has evolved significantly since 2012!
  • 🎉 Introduction of traits for code reuse.
  • 📉 PHP's performance has improved by 400%!
  • 🔮 New features include arrow functions and named arguments.
  • ✍️ Null coalescing simplifies variable assignment.
  • 🔃 Enums offer a structured way to handle constants.
  • 🔍 Type safety reduces coding errors.
  • 📏 PHP introduces trailing commas for cleaner syntax.
  • 💡 Generators allow memory-efficient operations.
  • 🤔 PHP is far from dead; it's thriving!

الجدول الزمني

  • 00:00:00 - 00:05:00

    The speaker discusses his long-term relationship with PHP, expressing frustration at comments claiming it is 'dead.' He reflects on his early experiences with PHP in 2013, highlighting the technological stagnation he felt at that time.

  • 00:05:00 - 00:10:00

    Acknowledging the need for type safety in PHP, the speaker anticipates discussing language improvements since 2012, specifically PHP 5.4, where features like traits were introduced to enhance code organization and composition.

  • 00:10:00 - 00:15:00

    As PHP evolved, the speaker appreciates the introduction of conveniences like array destructuring and variadic functions, noting the changes that allow developers to write cleaner and more efficient code. He expresses mixed feelings about these features but acknowledges their usefulness.

  • 00:15:00 - 00:20:00

    He discusses the null coalescing operator and naming arguments, highlighting how these advancements improve code readability and quality. The speaker shows excitement at PHP's shift towards modern programming practices with recent language updates.

  • 00:20:00 - 00:25:42

    Finally, the speaker emphasizes PHP's performance improvements, dispelling the myth of its slowness with statistical evidence. He encourages viewers to see the current state of PHP as a robust option for many applications, distinguishing it from outdated perceptions of the language.

اعرض المزيد

الخريطة الذهنية

فيديو أسئلة وأجوبة

  • Has PHP changed since 2012?

    Yes, PHP has undergone significant improvements since 2012, including new features such as traits, array destructuring, and type hinting.

  • What are traits in PHP?

    Traits allow for code reuse in classes, promoting composition over inheritance.

  • Is PHP still relevant in modern programming?

    Absolutely, PHP continues to evolve and includes many modern programming features.

  • What is the purpose of null coalescing in PHP?

    It allows developers to simplify assignments by providing a default value if the initial value is null.

  • Has the performance of PHP improved?

    Yes, PHP has experienced significant performance increases, with much faster execution times in recent versions.

  • What new syntax features have been added to PHP?

    New features include trailing commas, arrow functions, and named arguments.

  • What languages was PHP compared to in the video?

    The presenter compared PHP to JavaScript and Go, discussing PHP's advancements over time.

  • What are enums in PHP?

    Enums allow for defining a set of named constants, improving the organization of code.

  • What is type safety in PHP?

    Type safety ensures that variables are of a specific type, reducing errors in code.

  • What is the overall message about PHP?

    The video encourages viewers to reconsider their negative perceptions of PHP, highlighting its growth and capabilities.

عرض المزيد من ملخصات الفيديو

احصل على وصول فوري إلى ملخصات فيديو YouTube المجانية المدعومة بالذكاء الاصطناعي!
الترجمات
en
التمرير التلقائي:
  • 00:00:00
    let's do this every time I make a video
  • 00:00:01
    on PHP which is basically all the videos
  • 00:00:03
    I make I get the exact same
  • 00:00:07
    comment dead PHP sucks all the time
  • 00:00:10
    every time and most of the people that
  • 00:00:13
    think PHP is dead haven't looked at PHP
  • 00:00:16
    since like 2012 which is okay so maybe
  • 00:00:19
    he is saying exactly my experience which
  • 00:00:22
    is I haven't looked at PHP since 2012
  • 00:00:24
    2013 I think the last time I kid you not
  • 00:00:27
    I was such a PHP dork that in 20 13
  • 00:00:30
    there's get there's Go I mean node was
  • 00:00:34
    technically taking off I started a new
  • 00:00:39
    project I this was back when I was
  • 00:00:41
    trying to do startups I was always
  • 00:00:42
    trying to do little tool startups and
  • 00:00:43
    all that and uh I started a new project
  • 00:00:46
    using tortois SVN and PHP okay 2013 I
  • 00:00:51
    did that in 2013 I want you to know that
  • 00:00:53
    right now because if you don't know that
  • 00:00:55
    you just don't understand how painful my
  • 00:00:56
    life was I didn't know about all these
  • 00:00:58
    cool things you know this is back in
  • 00:01:00
    back in that day when I wasn't I
  • 00:01:02
    wasn't in my exploratory phase but
  • 00:01:05
    nonetheless tortois SVN in the day of
  • 00:01:07
    get 45.4 came out and listen things were
  • 00:01:11
    a lot different in 2012 I had just
  • 00:01:13
    graduated college a degree in accounting
  • 00:01:16
    for some reason this guy was still the
  • 00:01:19
    president over here this mov many and
  • 00:01:22
    honestly pretty good movie our music
  • 00:01:25
    okay first off can we just agree that
  • 00:01:27
    Looper was actually a pretty good show
  • 00:01:29
    okay whatever that guy's name is Joseph
  • 00:01:31
    Gordon Wyatt levit something like that I
  • 00:01:34
    like him okay I loved him on Third Rock
  • 00:01:36
    From the Sun okay I loved him there
  • 00:01:39
    Tommy I believe was his name and I I
  • 00:01:41
    love it now okay yeah I like it Bruce
  • 00:01:44
    Willis okay actor but Joseph Gordon
  • 00:01:47
    Wyatt levit whatever his name is loved
  • 00:01:50
    him went through this real weird hey ho
  • 00:01:53
    phase where we were always shouting hey
  • 00:01:55
    ho in the
  • 00:01:58
    songs hey
  • 00:02:00
    I think it's safe to say that a lot of
  • 00:02:03
    I'm no longer an accountant and PHP no
  • 00:02:06
    longer sucks I'm going to run you
  • 00:02:07
    through a bunch of the language changes
  • 00:02:09
    that have happened since around 2012
  • 00:02:11
    when PHP 5.4 came out and stick around
  • 00:02:14
    to the very end because we're going to
  • 00:02:16
    talk about types we got to talk about
  • 00:02:17
    type safety every time I talk about PHP
  • 00:02:20
    people just say yeah I just need types
  • 00:02:21
    we got to have types what about types do
  • 00:02:23
    you guys have tipes like yes this is me
  • 00:02:25
    I'm this person I'm literally that
  • 00:02:27
    person are you winning son
  • 00:02:31
    are you winning son no I am not winning
  • 00:02:34
    son I must have types it's the same
  • 00:02:36
    reason why I didn't choose Elixir as my
  • 00:02:38
    first functional language but instead o
  • 00:02:39
    camel because o camel is a very strict
  • 00:02:42
    beautiful static typing language and so
  • 00:02:45
    this is like this I've always had this
  • 00:02:47
    problem uh I do want to follow up on one
  • 00:02:49
    more thing he said that I was such a PHP
  • 00:02:51
    Fanboy and that was during the height of
  • 00:02:54
    my like maximum hours I worked per week
  • 00:02:56
    I was doing like 80 hours a week of PHP
  • 00:02:59
    5.4 or whatever it was I was into PHP so
  • 00:03:02
    I'm actually excited to see the new
  • 00:03:04
    things that have happened to PHP since
  • 00:03:05
    then and can I like feel that it's a
  • 00:03:08
    good language I don't know I don't know
  • 00:03:09
    I'm willing to have my mind remain open
  • 00:03:11
    for this can't leave my types we've got
  • 00:03:15
    types so I'm going to show you all the
  • 00:03:17
    different types you can do at the end
  • 00:03:19
    let's take PHP beat JavaScript to
  • 00:03:24
    types you should feel bad about yourself
  • 00:03:27
    if the language in which the original
  • 00:03:30
    author said it should have never been a
  • 00:03:32
    language was able to beat you to
  • 00:03:37
    types you should feel bad about yourself
  • 00:03:39
    okay you came
  • 00:03:41
    out like this just feel bad take a look
  • 00:03:44
    at these changes going all the way back
  • 00:03:46
    to 2012 for this one PHP 5.4 included
  • 00:03:49
    traits so instead of writing the same
  • 00:03:52
    method body over and over and over or
  • 00:03:54
    instead of abusing inheritance we now
  • 00:03:56
    have composition so you can have traits
  • 00:03:59
    and include those in every
  • 00:04:02
    class
  • 00:04:07
    what oh sh I think I like PHP oh my
  • 00:04:13
    goodness
  • 00:04:15
    what favoring composition over
  • 00:04:18
    inheritance PHP is actually better than
  • 00:04:24
    JavaScript I can't even believe it it's
  • 00:04:28
    real
  • 00:04:30
    it's real look I even put my name in
  • 00:04:31
    there what a nice guy short array syntax
  • 00:04:34
    imagine writing out the word array like
  • 00:04:38
    a caveman when you can just use square
  • 00:04:40
    brackets short array syntax allows you
  • 00:04:42
    to use square brackets thank you very
  • 00:04:44
    much let's go thank you we now have
  • 00:04:46
    array destructuring it used to be that
  • 00:04:48
    you have to assign an array to a
  • 00:04:50
    temporary variable and then reference
  • 00:04:52
    those Elements by index if you wanted to
  • 00:04:55
    assign them to other variables now you
  • 00:04:57
    can just use array destructuring and
  • 00:05:03
    D PHP actually is it's going to is it
  • 00:05:06
    really going to be a good language this
  • 00:05:07
    trait thing just blew me away and now
  • 00:05:10
    they're just doing basic conveniences
  • 00:05:11
    for every developer this is good this is
  • 00:05:14
    good like PHP welcome welcome to Modern
  • 00:05:17
    programming I like what I'm seeing
  • 00:05:18
    directly assign the variables from the
  • 00:05:21
    array we have first class vartic
  • 00:05:23
    functions so you can pass as many
  • 00:05:25
    arguments to a function as you want
  • 00:05:27
    using this I don't know how I feel about
  • 00:05:29
    vartic arguments I keep going back and
  • 00:05:31
    forth on them like if they're a good
  • 00:05:32
    idea or a bad idea I never know do you
  • 00:05:35
    know what I mean
  • 00:05:36
    like do I like them or do I not like
  • 00:05:39
    them because ultimately whenever I get
  • 00:05:42
    to vartic arguments I almost always want
  • 00:05:45
    to use a function with an array as AO or
  • 00:05:48
    a list as opposed to actually spelling
  • 00:05:50
    out the arguments one by one I almost
  • 00:05:52
    never actually
  • 00:05:54
    want vartic arguments like almost never
  • 00:05:58
    Almost Never there because any anytime
  • 00:06:00
    you're doing something programmatically
  • 00:06:02
    you almost always this right here right
  • 00:06:05
    you almost already have the nums array
  • 00:06:07
    and now you have to dot dot dot yeah
  • 00:06:08
    print f is a good example where it's
  • 00:06:10
    really really good but print f is
  • 00:06:12
    unusual you don't really use like
  • 00:06:14
    formatting functions I'm on for vartic
  • 00:06:17
    stuff I can completely concede that
  • 00:06:20
    ground and things like formatting or
  • 00:06:22
    string uh uh like rope string generation
  • 00:06:25
    anything like that totally on board with
  • 00:06:27
    that dot dot syntax
  • 00:06:30
    speaking of dot dott dot syntax you can
  • 00:06:31
    use that same syntax to spread or Splat
  • 00:06:35
    an array into an argument list for a
  • 00:06:37
    function ddy you use that same syntax to
  • 00:06:41
    spread or Splat an array into another
  • 00:06:44
    array so if you want to take all the
  • 00:06:45
    items from one array and put it into a
  • 00:06:48
    second array you can do that again this
  • 00:06:50
    is very very good also very very
  • 00:06:52
    interesting uh because this is a great
  • 00:06:55
    way to create a lot of memory on
  • 00:06:56
    accident that with this spread operator
  • 00:06:59
    we now have generators if you want to do
  • 00:07:02
    something memory intensive but in a
  • 00:07:04
    memory efficient way you can use a
  • 00:07:06
    generator so if you need to read a huge
  • 00:07:08
    file you don't have to load that whole
  • 00:07:10
    file into memory you can use a generator
  • 00:07:12
    to yield it line by line by line if you
  • 00:07:15
    ever need a new class but can't be
  • 00:07:17
    bothered to make a new file who has the
  • 00:07:19
    time you can create an anonymous class
  • 00:07:21
    an
  • 00:07:23
    an let's go I love that I love this idea
  • 00:07:30
    that that classes are just as much first
  • 00:07:33
    class citizens as functions this is
  • 00:07:35
    great this is great because there are
  • 00:07:37
    times where you just don't want to do
  • 00:07:39
    that and you really just need this right
  • 00:07:41
    here this is great this is actually
  • 00:07:43
    great wow PHP has aous class can
  • 00:07:46
    Implement an interface okay I you know
  • 00:07:48
    we're pausing this for a quick second
  • 00:07:50
    I'm hopping over to Twitter and maybe
  • 00:07:53
    PHP isn't all that bad
  • 00:07:58
    anymore
  • 00:08:00
    I am I'm we're shook okay we're shook
  • 00:08:04
    right now we're shook Oh
  • 00:08:08
    no just like every other class so this
  • 00:08:11
    is a great use case for when you need
  • 00:08:13
    one stupid little implementation but you
  • 00:08:15
    don't want to make a full class for it
  • 00:08:17
    yeah this is a big one I need you to pay
  • 00:08:20
    very very close attention we now have
  • 00:08:21
    trailing commas in function calls so
  • 00:08:25
    look very closely at email look at the
  • 00:08:27
    very end of the word email and watch
  • 00:08:29
    what's about to
  • 00:08:38
    happen
  • 00:08:39
    oh oh my
  • 00:08:42
    goodness oh boy I actually just added a
  • 00:08:44
    brand new emote just last night there
  • 00:08:46
    you go thank you can we get some WS in
  • 00:08:48
    there we need some wets that this is
  • 00:08:50
    just what I want this is what I want can
  • 00:08:52
    we get some WS I I need I need it I feel
  • 00:08:55
    it this is wet ass programming going on
  • 00:08:57
    right now oh my my goodness oh my
  • 00:09:00
    goodness
  • 00:09:02
    what oh love it I love it I love it
  • 00:09:08
    amazing we now have trailing commas in
  • 00:09:11
    method calls PHP rules this one's for
  • 00:09:14
    all okay well okay trailing commas ain't
  • 00:09:17
    making PHP rule but I okay I'm on your
  • 00:09:20
    team though it's pretty nice okay my
  • 00:09:23
    JavaScript friends I know you love your
  • 00:09:25
    arrow functions well look out friends
  • 00:09:28
    we've got Arrow function to RS honestly
  • 00:09:31
    are well they're they're a little bit
  • 00:09:33
    worse I don't like the FN at the
  • 00:09:34
    beginning to denote that it's a function
  • 00:09:36
    but hey we were I actually like the FN
  • 00:09:39
    at the beginning real talk I like that I
  • 00:09:41
    actually
  • 00:09:42
    I I've never really loved the Aros
  • 00:09:46
    syntax I like the idea of it being very
  • 00:09:50
    consistent I like this this is perfectly
  • 00:09:52
    fine with
  • 00:09:53
    me this is
  • 00:09:55
    beautiful work with what we've got we
  • 00:09:58
    have short short closures or Arrow
  • 00:10:01
    functions php7 brought us the null
  • 00:10:04
    coalescing operator so we can say the
  • 00:10:07
    username is equal to the username unless
  • 00:10:10
    the username is null in which case we'll
  • 00:10:12
    go with guest so we have this nice neat
  • 00:10:14
    null coalescing operator but we also
  • 00:10:17
    have the null coalescing assignment
  • 00:10:19
    operator which can shorthand all of that
  • 00:10:21
    and say if the username is set leave it
  • 00:10:23
    alone otherwise set it to
  • 00:10:26
    guest I understand what a PHP gasm is I
  • 00:10:29
    think I just had multiple PHP gasms in a
  • 00:10:32
    in a matter of minutes okay I don't know
  • 00:10:34
    what's going on
  • 00:10:36
    here but we're gming okay whatever it is
  • 00:10:39
    it's happening right now it's happening
  • 00:10:43
    speaking of nulls we used to have to do
  • 00:10:45
    something like this we would pull the
  • 00:10:47
    birthday off of the user and then before
  • 00:10:49
    we were allowed to call a method on
  • 00:10:51
    birthday we would check to see if
  • 00:10:53
    birthday existed yep you don't want to
  • 00:10:55
    call a method on null but now we have
  • 00:10:58
    the null chaining operator and we can
  • 00:11:00
    just say if birthday is not null call
  • 00:11:03
    the format function on it if it is null
  • 00:11:05
    just stop the chain right there we have
  • 00:11:08
    named arguments now it used to be that
  • 00:11:10
    if you wanted to skip over an optional
  • 00:11:12
    argument you had to leave a null in the
  • 00:11:14
    position of that argument but now we can
  • 00:11:16
    just name our arguments and pass them in
  • 00:11:18
    any order that we want PHP has
  • 00:11:21
    attributes now which in other languages
  • 00:11:22
    are probably called annotations but you
  • 00:11:24
    can add an
  • 00:11:27
    annotation
  • 00:11:31
    I actually like this okay I like that I
  • 00:11:34
    don't care what you have to say okay you
  • 00:11:36
    come in here with your oh PHP is
  • 00:11:38
    becoming C okay first off PHP doesn't
  • 00:11:42
    have a history of Triple E actions slash
  • 00:11:45
    they didn't give us the world they
  • 00:11:47
    didn't give us vs code I mean they did
  • 00:11:49
    give us WordPress which one could argue
  • 00:11:51
    is worse than vs code but nonetheless
  • 00:11:54
    look this looks great okay I love this
  • 00:11:56
    kind of stuff this kind of stuff to me
  • 00:11:58
    is fantastic I've never had a huge
  • 00:12:00
    problem with this uh because you know at
  • 00:12:03
    the end of the day you you have this you
  • 00:12:05
    have this whole problem with like go you
  • 00:12:08
    have to like specify everything and it
  • 00:12:09
    can kind of look a little you know I'm
  • 00:12:11
    over here maybe my go is not that great
  • 00:12:13
    yet I you know I but you know this kind
  • 00:12:15
    of stuff where you're just like doing
  • 00:12:16
    this you know I I don't know how I feel
  • 00:12:18
    about that either you know what I mean
  • 00:12:21
    to a class or meage or an argument or
  • 00:12:23
    property you can add an annotation to
  • 00:12:25
    almost anything and control a little bit
  • 00:12:27
    of behavior that way
  • 00:12:29
    keep this in mind we're going to look at
  • 00:12:31
    this again in a second this one is just
  • 00:12:33
    a huge massive Improvement it used to be
  • 00:12:36
    when you were catching an exception you
  • 00:12:38
    had to have a variable for that
  • 00:12:39
    exception even if you weren't going to
  • 00:12:41
    use it even if you were just simply
  • 00:12:42
    going to return false you had to have
  • 00:12:44
    that little e in there now look at this
  • 00:12:47
    watch this watch that e amazing no
  • 00:12:49
    longer needed if that's not reason
  • 00:12:51
    enough to switch to PHP I don't know
  • 00:12:53
    what to tell you remember those
  • 00:12:55
    attributes that I told you about
  • 00:12:56
    literally two seconds ago there's an
  • 00:12:58
    attribute that will will mark an
  • 00:12:59
    argument as sensitive and redact it from
  • 00:13:02
    all stack traces so you don't
  • 00:13:03
    accidentally end up logging something
  • 00:13:05
    you shouldn't at a language level very
  • 00:13:09
    okay that is genuinely awesome this is
  • 00:13:11
    genuinely awesome this is actually okay
  • 00:13:13
    so this is one of those things that I I
  • 00:13:15
    I I would say is is super cool that is
  • 00:13:18
    super cool can we all agree that that is
  • 00:13:20
    out of out of this world this
  • 00:13:23
    is this is great weird and probably very
  • 00:13:26
    slow maybe uh maybe it's only slow on
  • 00:13:29
    the exception case one could imagine
  • 00:13:31
    that it's slow purely on the exception
  • 00:13:33
    case right uh and it has no real world
  • 00:13:37
    imp implications on uh on performance in
  • 00:13:40
    any sense cool look at this switch
  • 00:13:43
    statement it's hideous it's huge we hate
  • 00:13:45
    it what we're doing is we're switching
  • 00:13:47
    on a status code and then in the body of
  • 00:13:49
    every status we're setting a message
  • 00:13:51
    variable there's got to be a better way
  • 00:13:54
    there is a better way we can use the
  • 00:13:56
    match statement now and assign the
  • 00:13:58
    message message variable to the result
  • 00:14:00
    of the match statement and look at 200
  • 00:14:02
    300 we can have multiple matches return
  • 00:14:05
    the same thing this is a much more
  • 00:14:07
    compact much more readable way to write
  • 00:14:10
    a switch statement that assigns a
  • 00:14:12
    variable we've got weak Maps now did you
  • 00:14:14
    know that PHP has weak maps you can set
  • 00:14:16
    an object as a key in a weak map where
  • 00:14:18
    you can't you can't do that in an array
  • 00:14:21
    and also weak maps are way better for
  • 00:14:23
    memory because they'll get garbage
  • 00:14:25
    collected when there's no references to
  • 00:14:27
    that object anymore PHP now has enums so
  • 00:14:29
    you can have an enum class where you
  • 00:14:31
    delineate the cases inside the body of
  • 00:14:33
    that class and those enums can also have
  • 00:14:36
    a value so if you want to use the words
  • 00:14:38
    draft published and archived in I mean
  • 00:14:42
    this is this ain't that that impressive
  • 00:14:44
    okay you know like you've been like I've
  • 00:14:46
    been having nothing but i' I've had
  • 00:14:48
    however many section gasms that are
  • 00:14:50
    available and then you just hit me with
  • 00:14:51
    a basic enum this this ain't it okay
  • 00:14:54
    this this this a this ain't impressing
  • 00:14:56
    me right now your codebase but you want
  • 00:14:57
    to use the value use 1 2 and three in
  • 00:14:59
    your database you can do that with a
  • 00:15:02
    backed enum that's not all that enums
  • 00:15:04
    can do you can add methods to your enum
  • 00:15:06
    classes in this case We'll add a method
  • 00:15:08
    that gives a userfriendly display to
  • 00:15:10
    each of the using the match statement
  • 00:15:13
    again and we're just matching against
  • 00:15:15
    this and all of our cases are our enum
  • 00:15:18
    cases one of the great things about
  • 00:15:21
    having I mean it's still better than
  • 00:15:22
    typescript enums can we all agree that
  • 00:15:23
    somehow typescript enums are actually
  • 00:15:26
    worse you know like at the the end of
  • 00:15:29
    the day as much you want to talk
  • 00:15:30
    about that enum that we just saw somehow
  • 00:15:34
    it's still wors okay Beast stop with
  • 00:15:37
    your C it's not C it's PHP I love today
  • 00:15:41
    okay birthday boy bisco by the way
  • 00:15:42
    YouTube you better wish bisco happy
  • 00:15:45
    birthday in the comments okay I expect
  • 00:15:47
    to see it I expect at least a hundred
  • 00:15:50
    happy birthdays when this video goes out
  • 00:15:53
    first class enums is you can now use
  • 00:15:55
    them as typ hints so if a method is
  • 00:15:58
    expected an enum you can hint that enum
  • 00:16:01
    class and that way PHP will validate
  • 00:16:04
    that the incoming argument is that enum
  • 00:16:07
    all right here we go we're going to run
  • 00:16:08
    through a bunch what does that mean
  • 00:16:10
    validate uh I'm curious what that means
  • 00:16:12
    if you just pass in any old in will it
  • 00:16:14
    say hey I can't validate it or will it
  • 00:16:16
    throw an exception if it doesn't match
  • 00:16:18
    does it have runtime implications a
  • 00:16:20
    little bit more curious about that last
  • 00:16:21
    one okay so this is the big one this is
  • 00:16:23
    the big one types types and more types
  • 00:16:24
    ways you can add types to PHP first you
  • 00:16:27
    can have typed arguments in this we say
  • 00:16:29
    A and B must both be integers this is a
  • 00:16:32
    scalar type hint You could also type
  • 00:16:33
    hint classes or enums like we showed
  • 00:16:35
    earlier you can have return types in
  • 00:16:37
    this case we're saying it must also
  • 00:16:39
    return an integer that makes enough
  • 00:16:41
    sense if you're adding two integers
  • 00:16:43
    together it should return an integer but
  • 00:16:46
    not all numbers are integers some
  • 00:16:48
    numbers are floats so you can also have
  • 00:16:50
    Union types you can say int or float
  • 00:16:53
    rock on rock on on that one I'm liking
  • 00:16:57
    that I'm liking that a lot
  • 00:16:59
    and it can return an INT or a float if
  • 00:17:01
    you wanted to add more than two numbers
  • 00:17:03
    together and you have a Vari adic
  • 00:17:04
    function you can also use types for that
  • 00:17:06
    no problem let's move on to a class here
  • 00:17:08
    we're saying that the argument input
  • 00:17:10
    must be of type Fu or bar this is the
  • 00:17:12
    union type that we just talked about but
  • 00:17:14
    you can also by the way I'm much more I
  • 00:17:17
    like Types on this side as opposed to
  • 00:17:19
    the other side call me crazy but I like
  • 00:17:22
    to read the type before I read the
  • 00:17:23
    variable name as opposed to reading the
  • 00:17:25
    variable name followed by the type okay
  • 00:17:27
    so you know like rust go and typescript
  • 00:17:29
    all have variables on that side whereas
  • 00:17:31
    like C you know that's kind of what I
  • 00:17:33
    grew up on was like C and Java you know
  • 00:17:36
    it's it's on the other side for me I've
  • 00:17:38
    just always liked it i' there's some
  • 00:17:39
    argument for it right that's all yeah
  • 00:17:42
    yeah you're not crazy it CPP shill maybe
  • 00:17:46
    uh type left uh stick in my brain yeah
  • 00:17:48
    it does are you crazy called it come on
  • 00:17:50
    pick you know it's just just just feels
  • 00:17:54
    right you know what I mean uh you know
  • 00:17:56
    and I also think that int array is
  • 00:17:58
    better than an array of int you know I I
  • 00:18:01
    I just don't I you know that's one thing
  • 00:18:03
    about go that always kind of irks me a
  • 00:18:04
    little bit but you know the fact that go
  • 00:18:06
    compil super super fast I don't give a I
  • 00:18:08
    don't give a damn you know what I mean
  • 00:18:10
    if you can if you can compile an entire
  • 00:18:12
    project in zero seconds you you know
  • 00:18:14
    what tell me how you define your ins I
  • 00:18:16
    I'm just fine with that you tell me and
  • 00:18:19
    I don't care like right like I have
  • 00:18:21
    various levels of what I care about and
  • 00:18:22
    that ain't it uh Hey thank you King I'll
  • 00:18:24
    say thank you in a second we're kind of
  • 00:18:25
    you know we're we're like in the middle
  • 00:18:27
    of something okay you know what I mean
  • 00:18:28
    you know what I mean dog okay it's
  • 00:18:30
    BEAST's birthday so I want you to say
  • 00:18:31
    happy birthday to him have an
  • 00:18:33
    intersection type where you say that the
  • 00:18:35
    argument input must be of type Fu and
  • 00:18:38
    bar which is really helpful when you're
  • 00:18:40
    trying to ensure that an argument
  • 00:18:41
    adheres to more than one interface but
  • 00:18:44
    you don't care what the type of object
  • 00:18:46
    is as long as it aderes to food and bar
  • 00:18:49
    you can do whatever you need to do you
  • 00:18:51
    want to get even crazier if you want to
  • 00:18:53
    ensure that input is Fu and bar or it's
  • 00:18:56
    nullable you can have a dis Jun normal
  • 00:18:59
    form type and I had
  • 00:19:01
    to he's about to say I had to go look up
  • 00:19:04
    that but a disjunctive normal form type
  • 00:19:06
    that literally sounds like a disease you
  • 00:19:08
    would be classified with with your
  • 00:19:10
    doctor
  • 00:19:12
    um it looks like you have disjunctive
  • 00:19:14
    normal form type learn those words for
  • 00:19:17
    this specific video you can have Fu and
  • 00:19:20
    bar or allow it to be null let's by the
  • 00:19:22
    way pick right now is like actually it
  • 00:19:25
    has pick I Can Feel It Coming pick I
  • 00:19:28
    know what you look at this uh that's
  • 00:19:30
    something that will make your uh your
  • 00:19:32
    balls
  • 00:19:33
    fall I thought you going to give me some
  • 00:19:35
    insightful comment pick I actually
  • 00:19:37
    thought I was going to get an insightful
  • 00:19:39
    comment instead I got this is g to make
  • 00:19:43
    your balls
  • 00:19:47
    fall so why you know this the benefit of
  • 00:19:50
    doing things live you know what I
  • 00:19:53
    mean look at another example we've been
  • 00:19:55
    typing arguments but you can also have
  • 00:19:57
    typed properties so if you look at this
  • 00:19:59
    class see that the public title property
  • 00:20:02
    is of type string and the public date
  • 00:20:04
    property is of type date time now this
  • 00:20:07
    is a little repetitive isn't it we've
  • 00:20:09
    got the two proper we've got the two
  • 00:20:11
    arguments in the Constructor and then in
  • 00:20:13
    the Constructor we have to set the class
  • 00:20:15
    level properties I totally forgot that
  • 00:20:17
    you have to do two underlines for
  • 00:20:19
    construct is that was that always
  • 00:20:21
    true was this always true I just I I
  • 00:20:25
    honestly can't remember it it's shocking
  • 00:20:27
    that I could do something for 80 hours a
  • 00:20:28
    week for multiple years and forget
  • 00:20:30
    it this is a little verbose this is how
  • 00:20:33
    we used to have to do it until the PHP
  • 00:20:35
    Gods introduced Constructor property
  • 00:20:37
    promotion and now you can put the
  • 00:20:39
    visibility in your Constructor signature
  • 00:20:42
    you can say public string title and it
  • 00:20:44
    will end up as a public property on your
  • 00:20:46
    class this I actually do like that that
  • 00:20:48
    t typescript also has this I'm not sure
  • 00:20:51
    if that's a JavaScript thing or just a
  • 00:20:52
    typescript thing but I've always liked
  • 00:20:54
    I've always liked this I think this is
  • 00:20:55
    very very good I don't want to have to
  • 00:20:56
    specify things twice always been been a
  • 00:20:58
    big fan uh C the C is called Constructor
  • 00:21:02
    promotion I don't love that you end up
  • 00:21:04
    with an empty Constructor body but I do
  • 00:21:06
    love that it reduces all of that boiler
  • 00:21:08
    plate if you want to Mark a property as
  • 00:21:10
    read only meaning that it can only be
  • 00:21:12
    initialized once and then never changed
  • 00:21:15
    there's a keyword for that you can say
  • 00:21:16
    that a property is read only and you can
  • 00:21:19
    do that in the Constructor as well if
  • 00:21:21
    your entire class is read only you can
  • 00:21:23
    mark the class as readon instead of
  • 00:21:25
    marking each individual property as only
  • 00:21:29
    a lot of stuff has changed if you have
  • 00:21:30
    by the way that actually is like these
  • 00:21:32
    type of changes also allow the just in
  • 00:21:35
    time compilation stuff to be much better
  • 00:21:37
    right you can do a lot more with a
  • 00:21:40
    language when you have more hints the
  • 00:21:42
    more things you have the faster you can
  • 00:21:44
    make it right the less you know about a
  • 00:21:46
    language the less you can really do you
  • 00:21:47
    have to like that's why in JavaScript if
  • 00:21:50
    you ever look at the memory of any uh
  • 00:21:52
    piece of JavaScript what you'll see is
  • 00:21:54
    that there's all these hidden pieces of
  • 00:21:56
    memory and they're like 30k 50k 10K
  • 00:21:59
    Associated effectively with every single
  • 00:22:02
    function because every single function
  • 00:22:04
    has a huge amount of assumptions being
  • 00:22:07
    calculated and kept track of such that
  • 00:22:09
    it can optimize it at some point right
  • 00:22:12
    and optimization is a function of length
  • 00:22:14
    of your of your function which is also
  • 00:22:16
    bizarre right so as your function gets
  • 00:22:19
    longer the more runs it has to take the
  • 00:22:21
    more memory it takes to actually
  • 00:22:23
    optimize it the more things it has to
  • 00:22:24
    keep track of it's very very uh it's
  • 00:22:27
    very interesting and so
  • 00:22:28
    PHP with inside like typing and all that
  • 00:22:31
    I think that you can do a lot more cool
  • 00:22:33
    stuff with how fast it runs by simply
  • 00:22:35
    knowing this information I love it
  • 00:22:37
    paying attention you might think PHP is
  • 00:22:39
    dead but alas it is not dead talk about
  • 00:22:41
    speed every time I make a video people
  • 00:22:43
    are like yeah PHP is so slow PHP between
  • 00:22:47
    like 5.6 and seven experienced a
  • 00:22:51
    400% performance increase and then I
  • 00:22:53
    think another 20% between seven and
  • 00:22:55
    eight I heard you're supposed to talk to
  • 00:22:57
    a doctor
  • 00:22:58
    if you exceed 400% is that still
  • 00:23:03
    true or or is that different
  • 00:23:06
    now or you can go longer than
  • 00:23:10
    400% giggity giggity long as you say
  • 00:23:13
    that is not as slow as you remember so
  • 00:23:16
    if you need something like 50,000
  • 00:23:18
    requests per second you should probably
  • 00:23:21
    still you should probably still not use
  • 00:23:23
    PHP for that but look at me listen to me
  • 00:23:25
    when have you personally needed 50,000
  • 00:23:28
    requests a
  • 00:23:29
    second how many users do you have
  • 00:23:33
    so that was so based that was like the
  • 00:23:37
    most base take of all time right there
  • 00:23:40
    that was so good that was so good dude
  • 00:23:43
    just just get
  • 00:23:46
    wrecked just get wrecked HP is fast
  • 00:23:51
    enough it is fast enough for most of
  • 00:23:53
    your use cases and if you need a
  • 00:23:55
    specialized use case use a specialized
  • 00:23:57
    language but the PHP of your is not the
  • 00:24:00
    same as the PHP of today it is much much
  • 00:24:03
    faster it is much much better and it is
  • 00:24:06
    not dead see you I really liked some of
  • 00:24:12
    the way the ways he said things I really
  • 00:24:13
    like that he called it the PHP of your
  • 00:24:15
    that was beautiful by the way go
  • 00:24:17
    subscribe to Aaron Francis what a great
  • 00:24:19
    guy not only is he a great guy great guy
  • 00:24:23
    when I met him in in IRL but also nice
  • 00:24:26
    guy on Twitter always super positive
  • 00:24:29
    sometimes I think he thinks that I'm a
  • 00:24:30
    little bit of a goober very nice guy go
  • 00:24:32
    give him a follow good guy I like him um
  • 00:24:36
    PHP plus HTM X stream I'm gonna be doing
  • 00:24:38
    golang because I'm cool uh you
  • 00:24:42
    know I'm I'm actually cool but I could
  • 00:24:46
    imagine that if I wasn't cool I would
  • 00:24:47
    consider PHP sorry Aaron for that that
  • 00:24:51
    last part uh
  • 00:24:53
    but
  • 00:24:56
    but Melky I get to do go to okay you
  • 00:24:59
    can't go back to rust I don't want to go
  • 00:25:00
    back to rust right now okay okay I did
  • 00:25:02
    two and a half years of rust and I use
  • 00:25:04
    rust like fulltime now or part-time and
  • 00:25:06
    sometimes you need a break from what
  • 00:25:07
    you're doing okay I don't want to be in
  • 00:25:09
    the rust world anymore I want off that
  • 00:25:11
    wild ride of rust okay o camel then but
  • 00:25:15
    the problem with o camel is nobody knows
  • 00:25:17
    what's happening when you show somebody
  • 00:25:19
    o camel no matter how many times you
  • 00:25:21
    hear in chat it's actually more
  • 00:25:22
    intuitive nobody thinks that okay nobody
  • 00:25:26
    thinks functional programming more
  • 00:25:28
    intuitive and all these people that tell
  • 00:25:30
    you that just have just drank so much
  • 00:25:33
    Kool-Aid they cannot see the forest for
  • 00:25:35
    the trees at all the
  • 00:25:38
    name is I could actually like PHP a j
الوسوم
  • PHP
  • programming
  • development
  • traits
  • type safety
  • null coalescing
  • enums
  • performance
  • modern PHP
  • coding