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 - Наука
the was the third video to me about this to watch, and the first video make me understand :)
The way you explain is amazing and easy to understand.. thanks
Excellent, Dave, thanks a lot.
Great explanation!
Thank you.
As always a great apportation by you
The simplicity of explanation speaks of high professionalism. Good job! Thanks.
good explanation ! thanks !
Спасибо 🙏💕
thank you it is well
Thanks 👍
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.
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
@@dave-hollingworth Thanks!
What php editor do you use and how do you run this code in command line?
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
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
];
}
}
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.
Thank you so much
What font is this?
In the editor and on the command line, DejaVu Sans Mono
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.
Ok, will add it to my list!
why did you write "Course" near $course. What is it called and what is its purpose.
It's the type declaration for the Course class. It declares the function argument as an object of the class "Course"
@@dave-hollingworth Thank you sir 🙏
@@dave-hollingworth Sir, Please make video tutorial on Laravel framework
👍
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
The wildcard character * doesn't need delimiting - so instead of `category_table`.`*` use `category_table`.*
@@dave-hollingworth Thank you