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

  Рет қаралды 4,543

Dave Hollingworth

Dave Hollingworth

Күн бұрын

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

Пікірлер: 28
@moraaoo4889
@moraaoo4889 7 ай бұрын
the was the third video to me about this to watch, and the first video make me understand :)
@emperoroftheearth3215
@emperoroftheearth3215 3 жыл бұрын
The way you explain is amazing and easy to understand.. thanks
@s3raph443
@s3raph443 Жыл бұрын
Спасибо 🙏💕
@persiansayed
@persiansayed 2 жыл бұрын
Great explanation! Thank you.
@williamsa51
@williamsa51 3 жыл бұрын
Excellent, Dave, thanks a lot.
@karenmelikyan377
@karenmelikyan377 Жыл бұрын
The simplicity of explanation speaks of high professionalism. Good job! Thanks.
@sameera-dananjaya-wijerathna
@sameera-dananjaya-wijerathna 2 жыл бұрын
good explanation ! thanks !
@giorgiobarone9784
@giorgiobarone9784 3 жыл бұрын
As always a great apportation by you
@mahfoudhani1252
@mahfoudhani1252 2 жыл бұрын
thank you it is well
@ademineshat
@ademineshat 3 жыл бұрын
Thanks 👍
@andrew.schaeffer4032
@andrew.schaeffer4032 Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
@@dave-hollingworth Thanks!
@marcinzawodnik6317
@marcinzawodnik6317 3 жыл бұрын
👍
@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.
@dave-hollingworth
@dave-hollingworth 3 жыл бұрын
Ok, will add it to my list!
@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 жыл бұрын
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 жыл бұрын
Thank you so much
@acos21
@acos21 3 жыл бұрын
What font is this?
@dave-hollingworth
@dave-hollingworth 3 жыл бұрын
In the editor and on the command line, DejaVu Sans Mono
@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 Жыл бұрын
@@dave-hollingworth Thank you sir 🙏
@johnydevlin
@johnydevlin Жыл бұрын
@@dave-hollingworth Sir, Please make video tutorial on Laravel framework
@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 жыл бұрын
The wildcard character * doesn't need delimiting - so instead of `category_table`.`*` use `category_table`.*
@mohamedab6440
@mohamedab6440 3 жыл бұрын
@@dave-hollingworth Thank you
The difference between use and require in PHP
3:48
Dave Hollingworth
Рет қаралды 4,1 М.
顔面水槽がブサイク過ぎるwwwww
00:58
はじめしゃちょー(hajime)
Рет қаралды 106 МЛН
Зомби Апокалипсис  часть 1 🤯#shorts
00:29
INNA SERG
Рет қаралды 7 МЛН
How To Choose Ramen Date Night 🍜
00:58
Jojo Sim
Рет қаралды 55 МЛН
PHP 2023. Ввод и вывод информации, типы данных PHP
30:41
WebDev с нуля. Канал Алекса Лущенко
Рет қаралды 4,9 М.
5 Reasons to Use PHP 8: New Syntax Features
7:02
Laravel Daily
Рет қаралды 29 М.
Example: Why We Need PHP Return Types
2:58
Laravel Daily
Рет қаралды 13 М.
PHP in 100 Seconds
2:21
Fireship
Рет қаралды 1,2 МЛН
10. Return Type Declarations - Object Oriented PHP
4:16
Gary Clarke
Рет қаралды 597
5 Rules For DTOs
17:56
Ardalis
Рет қаралды 35 М.
Client-side vs. server-side validation
8:01
Dave Hollingworth
Рет қаралды 13 М.
How to code PHP like a Pro (with a Tech Lead)
17:37
Lionel The Tech Lead
Рет қаралды 10 М.
Samsung vs Apple Vision Pro🤯
0:31
FilmBytes
Рет қаралды 416 М.
Вы поможете украсть ваш iPhone
0:56
Romancev768
Рет қаралды 620 М.
How about that uh?😎 #sneakers #airpods
0:13
Side Sphere
Рет қаралды 10 МЛН
Я Создал Новый Айфон!
0:59
FLV
Рет қаралды 3,3 МЛН