PHP Type Declarations: make your PHP code easier to read, and simpler to use

Поделиться
HTML-код
  • Опубликовано: 6 июн 2024
  • PHP for Beginners course: ➤ davehollingworth.net/phpy
    PHP MVC course: ► davehollingworth.net/phpmvcy
    CodeIgniter 4 course: ► davehollingworth.net/codeigni...
    PHP is a dynamically-typed language. This means that variables don't have a fixed type. However, PHP does have an optional strong type system: type declarations (previously known as type hints). In this video we'll see how using this will make your code simpler, easier to read, and easier to maintain.
    Resources:
    www.php.net/manual/en/languag...
    www.php.net/manual/en/languag...
    www.php.net/manual/en/languag...
    Code shown in the video:
    gist.github.com/daveh/24e87e3...
    00:00 Intro
    00:30 Types in PHP
    00:49 Type juggling
    02:00 Function arguments
    04:40 Type declarations
    07:05 Strict type mode
    08:15 Available types
    08:46 Return values
    09:00 Class properties
    09:20 Union types
    09:30 Nullable
    10:02 Summary
    #PHP #PHP8
  • НаукаНаука

Комментарии • 30

  • @moraaoo4889
    @moraaoo4889 8 месяцев назад +1

    the was the third video to me about this to watch, and the first video make me understand :)

  • @emperoroftheearth3215
    @emperoroftheearth3215 3 года назад +4

    The way you explain is amazing and easy to understand.. thanks

  • @williamsa51
    @williamsa51 3 года назад

    Excellent, Dave, thanks a lot.

  • @persiansayed
    @persiansayed 2 года назад

    Great explanation!
    Thank you.

  • @giorgiobarone9784
    @giorgiobarone9784 3 года назад

    As always a great apportation by you

  • @karenmelikyan377
    @karenmelikyan377 Год назад

    The simplicity of explanation speaks of high professionalism. Good job! Thanks.

  • @sameera-dananjaya-wijerathna
    @sameera-dananjaya-wijerathna 2 года назад

    good explanation ! thanks !

  • @s3raph443
    @s3raph443 Год назад +1

    Спасибо 🙏💕

  • @mahfoudhani1252
    @mahfoudhani1252 2 года назад

    thank you it is well

  • @ademineshat
    @ademineshat 3 года назад

    Thanks 👍

  • @andrew.schaeffer4032
    @andrew.schaeffer4032 Год назад +1

    Thanks for the helpful video! I'll probably be taking your courses and wonder if you have any suggestions for learning Apache? It keeps coming up, and I think it'd make my life a lot easier if I understood it instead of just guessing and copying code.

    • @dave-hollingworth
      @dave-hollingworth  Год назад +1

      Once Apache is installed, you don't usually need to configure it much, especially if you use something like XAMPP. There's a good tutorial here though if you're interested: www.guru99.com/apache.html

    • @andrew.schaeffer4032
      @andrew.schaeffer4032 Год назад +1

      @@dave-hollingworth Thanks!

  • @_Mikekkk
    @_Mikekkk 10 дней назад

    What php editor do you use and how do you run this code in command line?

    • @dave-hollingworth
      @dave-hollingworth  9 дней назад

      Visual Studio Code, running the code using the regular command prompt application. You can run interactive PHP with the -a flag, e.g. php -a

  • @sergey_gabrielyan1001
    @sergey_gabrielyan1001 2 года назад

    Hello, I want to know, is it possible to give type hinting to roles and permissions separately?
    public function getRoles(): array
    {
    if (Gate::allows('role_access')) {
    $roles = Role::with('permissions')->orderBy('id', 'DESC')->get();
    $permissions = Permission::all();
    return [
    'roles' => $roles,
    'permissions' => $permissions
    ];
    }
    }

    • @dave-hollingworth
      @dave-hollingworth  2 года назад +1

      I'm not sure what you mean - you can add type hints to only individual arguments or return values, you don't have to add them everywhere if you don't want to.

    • @sergey_gabrielyan1001
      @sergey_gabrielyan1001 2 года назад +1

      Thank you so much

  • @acos21
    @acos21 3 года назад

    What font is this?

    • @dave-hollingworth
      @dave-hollingworth  3 года назад +1

      In the editor and on the command line, DejaVu Sans Mono

  • @MobiusCoin
    @MobiusCoin 3 года назад

    So... I'm a WordPress theme developer so I'm not really a PHP developer. Can you do a video on the PHP interactive mode? I didn't know this existed until now lol.

  • @johnydevlin
    @johnydevlin Год назад

    why did you write "Course" near $course. What is it called and what is its purpose.

    • @dave-hollingworth
      @dave-hollingworth  Год назад

      It's the type declaration for the Course class. It declares the function argument as an object of the class "Course"

    • @johnydevlin
      @johnydevlin Год назад +1

      @@dave-hollingworth Thank you sir 🙏

    • @johnydevlin
      @johnydevlin Год назад +1

      @@dave-hollingworth Sir, Please make video tutorial on Laravel framework

  • @marcinzawodnik6317
    @marcinzawodnik6317 3 года назад

    👍

  • @mohamedab6440
    @mohamedab6440 3 года назад

    Error Number: 1054
    Unknown column 'category_table.*' in 'field list'
    SELECT `id`,`autor_name`,`title`, SUBSTRING(`content`, 1, 300) AS content,`image_url`,`show_first`, `date_creation`,`views`, `featured_for_menu`, `category_table`.`*` FROM `aricle_table`, `category_table` WHERE `aricle_table`. `id_category`= `category_table`.`id_category` ORDER BY `date_creation` DESC LIMIT 7 OFFSET 0
    Filename: C:/xampp/htdocs/ArabicBlog/system/database/DB_driver.php
    Line Number: 691

    • @dave-hollingworth
      @dave-hollingworth  3 года назад +2

      The wildcard character * doesn't need delimiting - so instead of `category_table`.`*` use `category_table`.*

    • @mohamedab6440
      @mohamedab6440 3 года назад +1

      @@dave-hollingworth Thank you