# ক্লাস এবং অবজেক্ট

## ক্লাস এবং অবজেক্ট এর পার্থক্য

একটি বাড়ি তৈরি করতে গেলে যেমন আমরা শুরুতে একটি নকশা বা ব্লু প্রিন্ট তৈরি করে নেই, পিএইচপিতেও তেমনি কোন অবজেক্ট কেমন হবে তা ডিফাইন করে দেওয়া হয় ক্লাস এর মাধ্যমে । অর্থাৎ অবজেক্ট এর ব্লু প্রিন্ট হলো ক্লাস, ক্লাস থেকে তৈরি করা হয় অবজেক্ট । একই ক্লাস থেকে তৈরি করা অবজেক্টগুলোর প্রত্যেকটি হলো ঐ ক্লাসের অবজেক্ট এর একটি ইন্সট্যান্স ।

## ক্লাস ডিফাইন করা

ক্লাস ডিফাইন করা খুবই সহজ, প্রথমে `class` কিওয়ার্ড, এরপর ক্লাসের নাম এরপর কোড ব্লকে থাকবে ক্লাস বডি । খুব সিম্পল একটি ক্লাসের উদাহরণ হতে পারে এরকম:

```php
<?php
class SimpleClass
{
}
```

এটা আসলে একটি ফাকা ক্লাস । এটি কোন কাজই করে না ।

## অবজেক্ট তৈরি করা

কোন ক্লাস থেকে ঐ ক্লাসের অবজেক্ট তৈরি করার জন্য আমরা `new` কিওয়ার্ডটি ব্যবহার করে থাকি । যেমন:

```php
<?php
$instance = new SimpleClass();
```

এখানে `$instance` একটি অবজেক্ট যার ক্লাস হলো `SimpleClass` । যদি কোন ভ্যারিয়েবল এ স্ট্রিং টাইপের ডাটা থাকে তবে ঐ ভ্যারিয়েবল এর আগে `new` ব্যবহার করেও নতুন অবজেক্ট তৈরি করা সম্ভব । এক্ষেত্রে ঐ ভ্যারিয়েবল এর যে ভ্যালু সেই নামের ক্লাস থেকে পিএইচপি অবজেক্ট তৈরি করার চেষ্টা করবে ।

```php
<?php
$className = 'SimpleClass';
$instance = new $className(); // SimpleClass()
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://php.howtocode.dev/oop/oop-class-and-objects.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
