Logo video2dn
  • Сохранить видео с ютуба
  • Категории
    • Музыка
    • Кино и Анимация
    • Автомобили
    • Животные
    • Спорт
    • Путешествия
    • Игры
    • Люди и Блоги
    • Юмор
    • Развлечения
    • Новости и Политика
    • Howto и Стиль
    • Diy своими руками
    • Образование
    • Наука и Технологии
    • Некоммерческие Организации
  • О сайте

Скачать или смотреть Understanding constructors and destructors in PHP

  • PHP Explained
  • 2025-04-06
  • 447
Understanding constructors and destructors in PHP
php constructorphp destructorphp constructor and destructorconstructor and destructor in php with exampledifference between constructor and destructor in php with example
  • ok logo

Скачать Understanding constructors and destructors in PHP бесплатно в качестве 4к (2к / 1080p)

У нас вы можете скачать бесплатно Understanding constructors and destructors in PHP или посмотреть видео с ютуба в максимальном доступном качестве.

Для скачивания выберите вариант из формы ниже:

  • Информация по загрузке:

Cкачать музыку Understanding constructors and destructors in PHP бесплатно в формате MP3:

Если иконки загрузки не отобразились, ПОЖАЛУЙСТА, НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если у вас возникли трудности с загрузкой, пожалуйста, свяжитесь с нами по контактам, указанным в нижней части страницы.
Спасибо за использование сервиса video2dn.com

Описание к видео Understanding constructors and destructors in PHP

Generally, we initialize object's properties separately after creating the object. This task will be much easier with the help of constructor.

Constructor allows to initialize an object's properties at the time of it's creation.

We use built-in PHP function __construct() to initialize object's properties. It consists of double underscore and construct() function.

If function __construct() available in the class then PHP will call it at the time of object creation and executes automatically. There is no need to call it separately.

Let's explain with an example.
See how the object obj1 is created. When we mention the class name, we are passing the property values. Once the object is created the constructor is called. Now come to the class. The constructor is available. The arguments are accepted. These values are then assigned to class properties. Check that we have used variable $this to assign the values to properties.

To be noted that $this is a keyword that refers to the current object. When obj1 is created $this refers to obj1, and then obj2.
class Toy
{
public $width;
public $height;
public $color;

function __construct($w, $h, $c)
{
$this-gt;width = $w;
$this-gt;height = $h;
$this-gt;color = $c;
}
}
$obj1 = new Toy(150, 550, "green");
$obj2 = new Toy(350, 850, "violet");

Like this class has destructor function that creates when an object is created. The destructor function executes automatically, if it is available in the class, when a script stop execution or at the end of the script.

Let's add destructor in our previous class Toy.
Destructor consists of double underscore followed by destruct() function.
Look at the class. We have added destructor. It's an empty function. It created when object obj1 is created. It executes at the end of the script automatically, there is no need to call it separately.
class Toy
{
public $width;
public $height;
public $color;

function __construct($w, $h, $c)
{
$this-gt;width = $w;
$this-gt;height = $h;
$this-gt;color = $c;
}

function __destruct()
{
}
}
$obj1 = new Toy(150, 550, "green");
$obj2 = new Toy(350, 850, "violet");

Constructors and destructors are highly significant parts of a class and OOP systems.

Комментарии

Информация по комментариям в разработке

Похожие видео

  • О нас
  • Контакты
  • Отказ от ответственности - Disclaimer
  • Условия использования сайта - TOS
  • Политика конфиденциальности

video2dn Copyright © 2023 - 2025

Контакты для правообладателей [email protected]