Hướng dẫn how can use class from another file in php? - làm thế nào có thể sử dụng lớp từ một tệp khác trong php?

Thích bài viết này? Chúng tôi đề nghị 

Nhập các lớp từ một tệp riêng biệt

Mặc dù rất hữu ích khi mô đun hóa mã của chúng tôi theo cách chúng tôi có, nhưng tốt nhất là nếu mỗi trang đề cập đến các sự kiện thực hiện thông qua các đối tượng sự kiện. Vì vậy, đối với mục đích bảo trì, tốt nhất là chuyển định nghĩa lớp vào một tệp riêng mà chúng ta có thể gọi từ các trang khác nhau. Để bắt đầu, hãy tạo một tệp mới. Đặt định nghĩa lớp trong tệp đó, như trong danh sách 5.

Liệt kê 5 tệp định nghĩa lớp riêng biệt (đối tượng.inc)

<?php
class Event {

  function Event($this_eventid){

    // Connect to database.
    $connection = mysql_connect ( "localhost", "myusername", "mypassword" ) ||
      die ( "Error connecting to database!" );

    // Get each entry
    $results = mysql_db_query ( "mysql", "SELECT * from events where eventid=$this_eventid");

    while ( $event = mysql_fetch_array ( $results ) ) {
      $this->eventid = $this_eventid;
      $this->month = $event["eventMonth"];
      $this->day = $event["eventDay"];
      $this->year = $event["eventYear"];
      $this->title = $event["eventTitle"];
      $this->description = $event["eventDesc"];
    }

    // Free resources.
    mysql_free_result ( $results );

  }
}
?>

Lưu ý rằng toàn bộ phần được đặt trong các phân định.

Để thực sự sử dụng đối tượng, chúng ta cần cung cấp định nghĩa lớp từ trong trang. Để làm điều đó, chúng ta có thể sử dụng hàm yêu cầu (), như được hiển thị trong Liệt kê 6.

Liệt kê 6 - làm cho định nghĩa lớp có sẵn (showevent.php)

<?php
  require("objects.inc");

  import_request_variables('pgc', '');

  $this_event = new Event($eventid);

  printf ( "<h2>%s</h2>", $this_event->title );
  printf ( "<h3>Date: %s/%s/%s</h3>", 
         $this_event->month, $this_event->day, $this_event->year );
  printf ( "<p>%s</p>", $this_event->description );
  printf ( "<a href='saveevent.php?editid=%s'>Edit this event</a>", $eventid );

?>

Hàm yêu cầu () hoạt động như thể tất cả các mã trong tệp đối tượng.INC được bao gồm trong tệp này tại thời điểm đó.

Bốn hàm cho phép bạn bao gồm mã từ một tệp khác: bao gồm (), abel (), bao gồm_once () và request_once (). Tất cả bốn có thể lấy một tệp hoặc URL cục bộ làm đầu vào. Sự khác biệt giữa các hàm bao gồm và yêu cầu là bao gồm () và bao gồm_once () chỉ cung cấp một cảnh báo nếu tài nguyên không thể được truy xuất; trong khi yêu cầu () và request_once () dừng xử lý trang. Bởi vì chúng tôi cần định nghĩa lớp để tiến hành, chúng tôi đang sử dụng yêu cầu ().

Các hàm bao gồm_once () và request_once () rất tiện dụng trong các tình huống trong đó nhiều tệp có thể tham chiếu cùng một mã bao gồm; Nếu tệp đã được bao gồm, nó sẽ không được đưa vào nữa. Bởi vì một hàm không thể được xác định lại sau khi được khai báo, hạn chế này có thể giúp ngăn ngừa lỗi.

Tóm tắt: Trong hướng dẫn này, bạn sẽ tìm hiểu cách sắp xếp các tệp lớp của mình và tự động tải chúng bằng PHP & NBSP; Chức năng

<?php
  require("objects.inc");

  import_request_variables('pgc', '');

  $this_event = new Event($eventid);

  printf ( "<h2>%s</h2>", $this_event->title );
  printf ( "<h3>Date: %s/%s/%s</h3>", 
         $this_event->month, $this_event->day, $this_event->year );
  printf ( "<p>%s</p>", $this_event->description );
  printf ( "<a href='saveevent.php?editid=%s'>Edit this event</a>", $eventid );

?>
6.: in this tutorial, you will learn how to organize your class files and load them automatically using PHP 
<?php
  require("objects.inc");

  import_request_variables('pgc', '');

  $this_event = new Event($eventid);

  printf ( "<h2>%s</h2>", $this_event->title );
  printf ( "<h3>Date: %s/%s/%s</h3>", 
         $this_event->month, $this_event->day, $this_event->year );
  printf ( "<p>%s</p>", $this_event->description );
  printf ( "<a href='saveevent.php?editid=%s'>Edit this event</a>", $eventid );

?>
6 function.

Đó là thực hành tốt để giữ mỗi lớp PHP trong một tệp riêng biệt. Ngoài ra, tên của lớp phải giống như tên tệp. Ví dụ: tệp

<?php
  require("objects.inc");

  import_request_variables('pgc', '');

  $this_event = new Event($eventid);

  printf ( "<h2>%s</h2>", $this_event->title );
  printf ( "<h3>Date: %s/%s/%s</h3>", 
         $this_event->month, $this_event->day, $this_event->year );
  printf ( "<p>%s</p>", $this_event->description );
  printf ( "<a href='saveevent.php?editid=%s'>Edit this event</a>", $eventid );

?>
7 phải chứa lớp
<?php
  require("objects.inc");

  import_request_variables('pgc', '');

  $this_event = new Event($eventid);

  printf ( "<h2>%s</h2>", $this_event->title );
  printf ( "<h3>Date: %s/%s/%s</h3>", 
         $this_event->month, $this_event->day, $this_event->year );
  printf ( "<p>%s</p>", $this_event->description );
  printf ( "<a href='saveevent.php?editid=%s'>Edit this event</a>", $eventid );

?>
8.

Trước khi sử dụng một lớp, bạn cần phải:

  • Đầu tiên, xác định lớp trong một tập tin.
  • Thứ hai, tải nó bằng câu lệnh
    <?php
      require("objects.inc");
    
      import_request_variables('pgc', '');
    
      $this_event = new Event($eventid);
    
      printf ( "<h2>%s</h2>", $this_event->title );
      printf ( "<h3>Date: %s/%s/%s</h3>", 
             $this_event->month, $this_event->day, $this_event->year );
      printf ( "<p>%s</p>", $this_event->description );
      printf ( "<a href='saveevent.php?editid=%s'>Edit this event</a>", $eventid );
    
    ?>
    9,

    . ├── index.php └── models └── Contact.php

    Code language: CSS (css)
    0,

    . ├── index.php └── models └── Contact.php

    Code language: CSS (css)
    1 hoặc

    . ├── index.php └── models └── Contact.php

    Code language: CSS (css)
    2.

Giả sử rằng bạn có cấu trúc thư mục dự án sau:

. ├── index.php └── models └── Contact.php

Code language: CSS (css)

Thư mục

. ├── index.php └── models └── Contact.php

Code language: CSS (css)
3 có tệp
<?php
  require("objects.inc");

  import_request_variables('pgc', '');

  $this_event = new Event($eventid);

  printf ( "<h2>%s</h2>", $this_event->title );
  printf ( "<h3>Date: %s/%s/%s</h3>", 
         $this_event->month, $this_event->day, $this_event->year );
  printf ( "<p>%s</p>", $this_event->description );
  printf ( "<a href='saveevent.php?editid=%s'>Edit this event</a>", $eventid );

?>
7 chứa lớp
<?php
  require("objects.inc");

  import_request_variables('pgc', '');

  $this_event = new Event($eventid);

  printf ( "<h2>%s</h2>", $this_event->title );
  printf ( "<h3>Date: %s/%s/%s</h3>", 
         $this_event->month, $this_event->day, $this_event->year );
  printf ( "<p>%s</p>", $this_event->description );
  printf ( "<a href='saveevent.php?editid=%s'>Edit this event</a>", $eventid );

?>
8 sau:

<?php class Contact { private $email; public function __construct(string $email) { $this->email = $email; } public function getEmail() { return $this->email; } }

Code language: HTML, XML (xml)

Từ tệp index.php, bạn có thể tải tệp

. ├── index.php └── models └── Contact.php

Code language: CSS (css)
6 và sử dụng lớp
<?php
  require("objects.inc");

  import_request_variables('pgc', '');

  $this_event = new Event($eventid);

  printf ( "<h2>%s</h2>", $this_event->title );
  printf ( "<h3>Date: %s/%s/%s</h3>", 
         $this_event->month, $this_event->day, $this_event->year );
  printf ( "<p>%s</p>", $this_event->description );
  printf ( "<a href='saveevent.php?editid=%s'>Edit this event</a>", $eventid );

?>
8 như sau:

<?php require_once 'models/Contact.php'; $contact = new Contact('');

Code language: HTML, XML (xml)

Giải pháp này hoạt động tốt nếu bạn có một số lượng nhỏ các tệp. Khi số lượng tệp tăng lên, câu lệnh

. ├── index.php └── models └── Contact.php

Code language: CSS (css)
0 không có tỷ lệ tốt.

Để giải quyết nó, bạn có thể xác định một hàm lấy tên lớp làm đối số và bao gồm tệp chứa định nghĩa lớp. Ví dụ:

<?php function load_model($class_name) { $path_to_file = 'models/' . $class_name . '.php'; if (file_exists($path_to_file)) { require $path_to_file; } }

Code language: HTML, XML (xml)

Hàm

. ├── index.php └── models └── Contact.php

Code language: CSS (css)
9 tìm tệp lớp trong thư mục

. ├── index.php └── models └── Contact.php

Code language: CSS (css)
3 và bao gồm nó nếu tệp tồn tại. Và bạn có thể đặt chức năng

<?php class Contact { private $email; public function __construct(string $email) { $this->email = $email; } public function getEmail() { return $this->email; } }

Code language: HTML, XML (xml)
1 trong tệp

<?php class Contact { private $email; public function __construct(string $email) { $this->email = $email; } public function getEmail() { return $this->email; } }

Code language: HTML, XML (xml)
2:

. ├── functions.php ├── index.php └── models └── Contact.php

Code language: plaintext (plaintext)

Để sử dụng chức năng

<?php class Contact { private $email; public function __construct(string $email) { $this->email = $email; } public function getEmail() { return $this->email; } }

Code language: HTML, XML (xml)
1 trong tệp

<?php class Contact { private $email; public function __construct(string $email) { $this->email = $email; } public function getEmail() { return $this->email; } }

Code language: HTML, XML (xml)
4, bạn có thể bao gồm tệp

<?php class Contact { private $email; public function __construct(string $email) { $this->email = $email; } public function getEmail() { return $this->email; } }

Code language: HTML, XML (xml)
2 và gọi hàm

<?php class Contact { private $email; public function __construct(string $email) { $this->email = $email; } public function getEmail() { return $this->email; } }

Code language: HTML, XML (xml)
1:

<?php require_once 'functions.php'; load_model('Person'); $person = new Person();

Code language: HTML, XML (xml)

Trình tải tự động với chức năng SPL_AUTOLOAD_REGISTER ()

Php 5.1.2 đã giới thiệu chức năng

<?php
  require("objects.inc");

  import_request_variables('pgc', '');

  $this_event = new Event($eventid);

  printf ( "<h2>%s</h2>", $this_event->title );
  printf ( "<h3>Date: %s/%s/%s</h3>", 
         $this_event->month, $this_event->day, $this_event->year );
  printf ( "<p>%s</p>", $this_event->description );
  printf ( "<a href='saveevent.php?editid=%s'>Edit this event</a>", $eventid );

?>
6 tự động tải tệp lớp bất cứ khi nào bạn sử dụng một lớp chưa được tải.

Php 7.2.0 không dùng nữa chức năng ma thuật

<?php class Contact { private $email; public function __construct(string $email) { $this->email = $email; } public function getEmail() { return $this->email; } }

Code language: HTML, XML (xml)
8 và được khuyến nghị sử dụng chức năng
<?php
  require("objects.inc");

  import_request_variables('pgc', '');

  $this_event = new Event($eventid);

  printf ( "<h2>%s</h2>", $this_event->title );
  printf ( "<h3>Date: %s/%s/%s</h3>", 
         $this_event->month, $this_event->day, $this_event->year );
  printf ( "<p>%s</p>", $this_event->description );
  printf ( "<a href='saveevent.php?editid=%s'>Edit this event</a>", $eventid );

?>
6 thay thế.

Khi bạn sử dụng một lớp chưa được tải, PHP sẽ tự động tìm kiếm cuộc gọi chức năng

<?php
  require("objects.inc");

  import_request_variables('pgc', '');

  $this_event = new Event($eventid);

  printf ( "<h2>%s</h2>", $this_event->title );
  printf ( "<h3>Date: %s/%s/%s</h3>", 
         $this_event->month, $this_event->day, $this_event->year );
  printf ( "<p>%s</p>", $this_event->description );
  printf ( "<a href='saveevent.php?editid=%s'>Edit this event</a>", $eventid );

?>
6.

Hàm

<?php
  require("objects.inc");

  import_request_variables('pgc', '');

  $this_event = new Event($eventid);

  printf ( "<h2>%s</h2>", $this_event->title );
  printf ( "<h3>Date: %s/%s/%s</h3>", 
         $this_event->month, $this_event->day, $this_event->year );
  printf ( "<p>%s</p>", $this_event->description );
  printf ( "<a href='saveevent.php?editid=%s'>Edit this event</a>", $eventid );

?>
6 chấp nhận chức năng gọi lại và gọi nó khi bạn cố gắng tạo sử dụng một lớp chưa được tải.

Để sử dụng chức năng

<?php
  require("objects.inc");

  import_request_variables('pgc', '');

  $this_event = new Event($eventid);

  printf ( "<h2>%s</h2>", $this_event->title );
  printf ( "<h3>Date: %s/%s/%s</h3>", 
         $this_event->month, $this_event->day, $this_event->year );
  printf ( "<p>%s</p>", $this_event->description );
  printf ( "<a href='saveevent.php?editid=%s'>Edit this event</a>", $eventid );

?>
6, bạn có thể chuyển chức năng

<?php require_once 'models/Contact.php'; $contact = new Contact('');

Code language: HTML, XML (xml)
3 cho nó như sau:

<?php function load_model($class_name) { $path_to_file = 'models/' . $class_name . '.php'; if (file_exists($path_to_file)) { require $path_to_file; } } spl_autoload_register('load_model');

Code language: HTML, XML (xml)

Và từ tệp

<?php class Contact { private $email; public function __construct(string $email) { $this->email = $email; } public function getEmail() { return $this->email; } }

Code language: HTML, XML (xml)
4, bạn không cần gọi chức năng

<?php class Contact { private $email; public function __construct(string $email) { $this->email = $email; } public function getEmail() { return $this->email; } }

Code language: HTML, XML (xml)
1 bất cứ khi nào bạn sử dụng một lớp trong thư mục

. ├── index.php └── models └── Contact.php

Code language: CSS (css)
3:

<?php require 'functions.php'; $contact = new Contact('');

Code language: HTML, XML (xml)

Nhiều chức năng tự động tải

Hàm

<?php
  require("objects.inc");

  import_request_variables('pgc', '');

  $this_event = new Event($eventid);

  printf ( "<h2>%s</h2>", $this_event->title );
  printf ( "<h3>Date: %s/%s/%s</h3>", 
         $this_event->month, $this_event->day, $this_event->year );
  printf ( "<p>%s</p>", $this_event->description );
  printf ( "<a href='saveevent.php?editid=%s'>Edit this event</a>", $eventid );

?>
6 cho phép bạn sử dụng nhiều chức năng tự động tải. Hàm
<?php
  require("objects.inc");

  import_request_variables('pgc', '');

  $this_event = new Event($eventid);

  printf ( "<h2>%s</h2>", $this_event->title );
  printf ( "<h3>Date: %s/%s/%s</h3>", 
         $this_event->month, $this_event->day, $this_event->year );
  printf ( "<p>%s</p>", $this_event->description );
  printf ( "<a href='saveevent.php?editid=%s'>Edit this event</a>", $eventid );

?>
6 sẽ tạo ra một hàng đợi các chức năng tự động tải và chạy qua từng chức năng theo thứ tự mà chúng được xác định.

Ví dụ:

<?php
  require("objects.inc");

  import_request_variables('pgc', '');

  $this_event = new Event($eventid);

  printf ( "<h2>%s</h2>", $this_event->title );
  printf ( "<h3>Date: %s/%s/%s</h3>", 
         $this_event->month, $this_event->day, $this_event->year );
  printf ( "<p>%s</p>", $this_event->description );
  printf ( "<a href='saveevent.php?editid=%s'>Edit this event</a>", $eventid );

?>
0

Trong ví dụ này, PHP sẽ chạy tuần tự

<?php require_once 'models/Contact.php'; $contact = new Contact('');

Code language: HTML, XML (xml)
9,

<?php function load_model($class_name) { $path_to_file = 'models/' . $class_name . '.php'; if (file_exists($path_to_file)) { require $path_to_file; } }

Code language: HTML, XML (xml)
0 và

<?php function load_model($class_name) { $path_to_file = 'models/' . $class_name . '.php'; if (file_exists($path_to_file)) { require $path_to_file; } }

Code language: HTML, XML (xml)
1 để tải các tệp lớp.

Để chứng minh điều này, hãy để Lôi tạo một thư mục mới có tên

<?php function load_model($class_name) { $path_to_file = 'models/' . $class_name . '.php'; if (file_exists($path_to_file)) { require $path_to_file; } }

Code language: HTML, XML (xml)
2 lưu trữ các tệp lớp dịch vụ và tạo tệp

<?php function load_model($class_name) { $path_to_file = 'models/' . $class_name . '.php'; if (file_exists($path_to_file)) { require $path_to_file; } }

Code language: HTML, XML (xml)
3 bên trong thư mục

<?php function load_model($class_name) { $path_to_file = 'models/' . $class_name . '.php'; if (file_exists($path_to_file)) { require $path_to_file; } }

Code language: HTML, XML (xml)
2.

Sau đây xác định lớp

<?php function load_model($class_name) { $path_to_file = 'models/' . $class_name . '.php'; if (file_exists($path_to_file)) { require $path_to_file; } }

Code language: HTML, XML (xml)
5:

<?php
  require("objects.inc");

  import_request_variables('pgc', '');

  $this_event = new Event($eventid);

  printf ( "<h2>%s</h2>", $this_event->title );
  printf ( "<h3>Date: %s/%s/%s</h3>", 
         $this_event->month, $this_event->day, $this_event->year );
  printf ( "<p>%s</p>", $this_event->description );
  printf ( "<a href='saveevent.php?editid=%s'>Edit this event</a>", $eventid );

?>
1

Thư mục dự án bây giờ trông như thế này:

<?php
  require("objects.inc");

  import_request_variables('pgc', '');

  $this_event = new Event($eventid);

  printf ( "<h2>%s</h2>", $this_event->title );
  printf ( "<h3>Date: %s/%s/%s</h3>", 
         $this_event->month, $this_event->day, $this_event->year );
  printf ( "<p>%s</p>", $this_event->description );
  printf ( "<a href='saveevent.php?editid=%s'>Edit this event</a>", $eventid );

?>
2

Trong tệp

<?php class Contact { private $email; public function __construct(string $email) { $this->email = $email; } public function getEmail() { return $this->email; } }

Code language: HTML, XML (xml)
2, bạn có thể xác định một hàm tải các lớp từ thư mục

<?php function load_model($class_name) { $path_to_file = 'models/' . $class_name . '.php'; if (file_exists($path_to_file)) { require $path_to_file; } }

Code language: HTML, XML (xml)
2 và chuyển tên chức năng đến hàm
<?php
  require("objects.inc");

  import_request_variables('pgc', '');

  $this_event = new Event($eventid);

  printf ( "<h2>%s</h2>", $this_event->title );
  printf ( "<h3>Date: %s/%s/%s</h3>", 
         $this_event->month, $this_event->day, $this_event->year );
  printf ( "<p>%s</p>", $this_event->description );
  printf ( "<a href='saveevent.php?editid=%s'>Edit this event</a>", $eventid );

?>
6 như thế này:

<?php
  require("objects.inc");

  import_request_variables('pgc', '');

  $this_event = new Event($eventid);

  printf ( "<h2>%s</h2>", $this_event->title );
  printf ( "<h3>Date: %s/%s/%s</h3>", 
         $this_event->month, $this_event->day, $this_event->year );
  printf ( "<p>%s</p>", $this_event->description );
  printf ( "<a href='saveevent.php?editid=%s'>Edit this event</a>", $eventid );

?>
3

Từ

<?php class Contact { private $email; public function __construct(string $email) { $this->email = $email; } public function getEmail() { return $this->email; } }

Code language: HTML, XML (xml)
4, bạn có thể sử dụng các lớp
<?php
  require("objects.inc");

  import_request_variables('pgc', '');

  $this_event = new Event($eventid);

  printf ( "<h2>%s</h2>", $this_event->title );
  printf ( "<h3>Date: %s/%s/%s</h3>", 
         $this_event->month, $this_event->day, $this_event->year );
  printf ( "<p>%s</p>", $this_event->description );
  printf ( "<a href='saveevent.php?editid=%s'>Edit this event</a>", $eventid );

?>
8 và

<?php function load_model($class_name) { $path_to_file = 'models/' . $class_name . '.php'; if (file_exists($path_to_file)) { require $path_to_file; } }

Code language: HTML, XML (xml)
5 như sau:

<?php
  require("objects.inc");

  import_request_variables('pgc', '');

  $this_event = new Event($eventid);

  printf ( "<h2>%s</h2>", $this_event->title );
  printf ( "<h3>Date: %s/%s/%s</h3>", 
         $this_event->month, $this_event->day, $this_event->year );
  printf ( "<p>%s</p>", $this_event->description );
  printf ( "<a href='saveevent.php?editid=%s'>Edit this event</a>", $eventid );

?>
4

Output:

<?php
  require("objects.inc");

  import_request_variables('pgc', '');

  $this_event = new Event($eventid);

  printf ( "<h2>%s</h2>", $this_event->title );
  printf ( "<h3>Date: %s/%s/%s</h3>", 
         $this_event->month, $this_event->day, $this_event->year );
  printf ( "<p>%s</p>", $this_event->description );
  printf ( "<a href='saveevent.php?editid=%s'>Edit this event</a>", $eventid );

?>
5

Giống như các lớp, bạn cũng có thể tải các giao diện và đặc điểm sử dụng cùng một chức năng tự động tải.

Bản tóm tắt

  • Hàm tự động tải tải một lớp, giao diện hoặc tính trạng từ tệp PHP.
  • Sử dụng chức năng
    <?php
      require("objects.inc");
    
      import_request_variables('pgc', '');
    
      $this_event = new Event($eventid);
    
      printf ( "<h2>%s</h2>", $this_event->title );
      printf ( "<h3>Date: %s/%s/%s</h3>", 
             $this_event->month, $this_event->day, $this_event->year );
      printf ( "<p>%s</p>", $this_event->description );
      printf ( "<a href='saveevent.php?editid=%s'>Edit this event</a>", $eventid );
    
    ?>
    6 để tự động tải các lớp, giao diện và đặc điểm.

Bạn có thấy hướng dẫn này hữu ích không?

Làm thế nào chúng ta có thể kết nối hai tệp trong PHP?

Có thể chèn nội dung của một tệp PHP vào tệp PHP khác (trước khi máy chủ thực thi nó), với câu lệnh bao gồm hoặc yêu cầu. Các câu lệnh bao gồm và yêu cầu là giống hệt nhau, ngoại trừ khi thất bại: yêu cầu sẽ tạo ra một lỗi nghiêm trọng (e_compile_error) và dừng tập lệnh.with the include or require statement. The include and require statements are identical, except upon failure: require will produce a fatal error (E_COMPILE_ERROR) and stop the script.

Làm cách nào để gọi hàm PHP từ một tệp khác?

Để gọi một hàm từ một tệp khác trong PHP, bạn cần nhập tệp nơi hàm được xác định trước khi gọi nó.Bạn có thể nhập một tệp PHP bằng cách sử dụng câu lệnh yêu cầu.Để gọi hàm lời chào () từ một tệp khác, bạn cần nhập thư viện.import the file where the function is defined before calling it. You can import a PHP file by using the require statement. To call the greetings() function from another file, you need to import the library.

Các lớp được tải trong PHP như thế nào?

Các lớp tải PHP được sử dụng để khai báo đối tượng của nó, vv trong các ứng dụng hướng đối tượng.Trình phân tích cú pháp PHP tự động tải nó, nếu nó được đăng ký với hàm spl_autoload_register ().PHP parser loads it automatically, if it is registered with spl_autoload_register() function.

Classin PHP là gì?

Lớp là một loại dữ liệu do lập trình viên xác định, bao gồm các phương thức cục bộ và các biến cục bộ.Lớp học là một tập hợp các đối tượng.Đối tượng có thuộc tính và hành vi.a programmer-defined data type, which includes local methods and local variables. Class is a collection of objects. Object has properties and behavior.