- Популярные видео
- Авто
- Видео-блоги
- ДТП, аварии
- Для маленьких
- Еда, напитки
- Животные
- Закон и право
- Знаменитости
- Игры
- Искусство
- Комедии
- Красота, мода
- Кулинария, рецепты
- Люди
- Мото
- Музыка
- Мультфильмы
- Наука, технологии
- Новости
- Образование
- Политика
- Праздники
- Приколы
- Природа
- Происшествия
- Путешествия
- Развлечения
- Ржач
- Семья
- Сериалы
- Спорт
- Стиль жизни
- ТВ передачи
- Танцы
- Технологии
- Товары
- Ужасы
- Фильмы
- Шоу-бизнес
- Юмор
OOP Constructor | __construct in PHP | object initialization | Property Promotion #kody_az
PHP-də constructor — bir sinifin içində yerləşən xüsusi bir metoddur və yeni obyekt yaradılan anda avtomatik işləyir.
Onun əsas məqsədi obyektin ilkin vəziyyətini hazırlamaqdır — məsələn, obyektin xüsusiyyətlərini (property) təyin etmək və ya hər hansı başlanğıc əməliyyatları yerinə yetirmək.
Constructorun Əsas Xüsusiyyətləri
• Həmişə __construct adı ilə adlandırılır.
• new açar sözü ilə obyekt yaradıldıqda avtomatik olaraq çağırılır.
• Parametrlər qəbul edə bilər, beləliklə obyekt yaradılarkən məlumat ötürmək mümkündür.
• Obyektin qurulması üçün əlavə kod yazmağa ehtiyac qalmır, kod daha qısa və səliqəli olur.
Constructor Niyə Vacibdir?
• Avtomatik Başlanğıc: Obyekt yaradılan anda xüsusiyyətlərin və lazımi dəyərlərin təyini avtomatik olur.
• Daha Təmiz Kod: Constructor sayəsində əlavə setup kodu yazmadan obyekt dərhal işlək vəziyyətdə olur.
• Sabitlik və Təhlükəsizlik: Hər obyekt doğru və tam vəziyyətdə qurulduğundan səhvlər azalır.
• Çeviklik: Müxtəlif obyektlər yaratmaq üçün konstruktora müxtəlif parametrlər ötürmək mümkündür.
PHP 8 versiyasından etibarən, constructor property promotion funksiyası gəldi.
Bu xüsusiyyət sayəsində sinifin xüsusiyyətlərini konstruktorun parametrləri içində birbaşa elan və başlatmaq mümkündür.
====
In PHP, a constructor is a special method inside a class that is automatically called when a new object of that class is created.
Its main job is to prepare or initialize the object — for example, setting up property values or running some setup logic right when the object comes into existence.
Key Features of a Constructor
• It is always named __construct.
• It runs immediately when you create an object with the new keyword.
• It can accept parameters, which allows you to pass data into the object during creation.
• It helps avoid writing extra setup code after creating an object, making code shorter and cleaner.
Why Constructors Are Important
• Automatic Initialization: Constructors allow you to automatically set up properties, connections, or any important state an object needs.
• Cleaner Code: Without constructors, you’d have to remember to manually initialize everything every time you create an object.
• Consistency: Constructors guarantee that every object starts its life correctly set up, reducing bugs.
• Flexibility: You can pass different arguments to the constructor to create slightly different versions of an object based on different conditions.
Constructor Property Promotion
From PHP 8 onward, you can declare class properties directly in the constructor’s parameter list.
This saves time by combining property declaration, visibility setting, type hinting, and initialization all in one place.
#kody_az #kodyaz #php #phpcode #laravel #phpprogramming #viral #viralcode #viralvideo #random #code #coder #azerbaycan #azerbaijan #baku #baki #programming #programmer #codes #hazırlıq #hazirliq #kurs #kurslar #course #courses #online #onlinecourses #test #quiz
Видео OOP Constructor | __construct in PHP | object initialization | Property Promotion #kody_az канала KODY•AZ
Onun əsas məqsədi obyektin ilkin vəziyyətini hazırlamaqdır — məsələn, obyektin xüsusiyyətlərini (property) təyin etmək və ya hər hansı başlanğıc əməliyyatları yerinə yetirmək.
Constructorun Əsas Xüsusiyyətləri
• Həmişə __construct adı ilə adlandırılır.
• new açar sözü ilə obyekt yaradıldıqda avtomatik olaraq çağırılır.
• Parametrlər qəbul edə bilər, beləliklə obyekt yaradılarkən məlumat ötürmək mümkündür.
• Obyektin qurulması üçün əlavə kod yazmağa ehtiyac qalmır, kod daha qısa və səliqəli olur.
Constructor Niyə Vacibdir?
• Avtomatik Başlanğıc: Obyekt yaradılan anda xüsusiyyətlərin və lazımi dəyərlərin təyini avtomatik olur.
• Daha Təmiz Kod: Constructor sayəsində əlavə setup kodu yazmadan obyekt dərhal işlək vəziyyətdə olur.
• Sabitlik və Təhlükəsizlik: Hər obyekt doğru və tam vəziyyətdə qurulduğundan səhvlər azalır.
• Çeviklik: Müxtəlif obyektlər yaratmaq üçün konstruktora müxtəlif parametrlər ötürmək mümkündür.
PHP 8 versiyasından etibarən, constructor property promotion funksiyası gəldi.
Bu xüsusiyyət sayəsində sinifin xüsusiyyətlərini konstruktorun parametrləri içində birbaşa elan və başlatmaq mümkündür.
====
In PHP, a constructor is a special method inside a class that is automatically called when a new object of that class is created.
Its main job is to prepare or initialize the object — for example, setting up property values or running some setup logic right when the object comes into existence.
Key Features of a Constructor
• It is always named __construct.
• It runs immediately when you create an object with the new keyword.
• It can accept parameters, which allows you to pass data into the object during creation.
• It helps avoid writing extra setup code after creating an object, making code shorter and cleaner.
Why Constructors Are Important
• Automatic Initialization: Constructors allow you to automatically set up properties, connections, or any important state an object needs.
• Cleaner Code: Without constructors, you’d have to remember to manually initialize everything every time you create an object.
• Consistency: Constructors guarantee that every object starts its life correctly set up, reducing bugs.
• Flexibility: You can pass different arguments to the constructor to create slightly different versions of an object based on different conditions.
Constructor Property Promotion
From PHP 8 onward, you can declare class properties directly in the constructor’s parameter list.
This saves time by combining property declaration, visibility setting, type hinting, and initialization all in one place.
#kody_az #kodyaz #php #phpcode #laravel #phpprogramming #viral #viralcode #viralvideo #random #code #coder #azerbaycan #azerbaijan #baku #baki #programming #programmer #codes #hazırlıq #hazirliq #kurs #kurslar #course #courses #online #onlinecourses #test #quiz
Видео OOP Constructor | __construct in PHP | object initialization | Property Promotion #kody_az канала KODY•AZ
kodyaz code kody_az kurs course hazirliq hazırlıq kurslar magistr telebe proqramlasdırma programming programlasdirma proqramlasdirma программировагие курсы azerbaycan azerbaycanca azərbaycan azərbaycanca rusca на русском english kod film filmləri hazırlamaq hazirlamaq nece how как фильмы abituryent imtahan dim cavablar magistratura php constructor tutorial constructor oop object-oriented programming class PHP 8 property promotion full course class structure
Комментарии отсутствуют
Информация о видео
26 апреля 2025 г. 21:43:00
00:48:24
Другие видео канала




















