> For the complete documentation index, see [llms.txt](https://docs.layraweb.com.tr/merhaba/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.layraweb.com.tr/merhaba/php-tarafi/konular/siniflar-ve-nesneler/kurucu-yontemler.md).

# Kurucu Yöntemler

PHP'de sınıflar ve nesneler oluşturulurken, bir kurucu yöntem kullanılarak nesnelerin özellikleri tanımlanır. Kurucu yöntem, bir sınıf örneği oluşturulduğunda otomatik olarak çağrılan bir yöntemdir.

Kurucu yöntem, "\_\_construct()" olarak adlandırılır ve herhangi bir parametre alabilir veya almayabilir. Sınıfın özellikleri ve diğer işlevlerinin başlatılması için kullanılır. Örneğin, bir hayvan sınıfı oluşturulurken, hayvanın ismi, yaşam alanı ve diğer özellikleri kurucu yöntemde tanımlanabilir.

İşte basit bir örnek:

```php
class Hayvan {
   public $isim;
   public $yasam_alani;

   function __construct($isim, $yasam_alani) {
      $this->isim = $isim;
      $this->yasam_alani = $yasam_alani;
   }

   function getInfo() {
      echo "Hayvanın ismi: " . $this->isim . "<br>";
      echo "Hayvanın yaşam alanı: " . $this->yasam_alani . "<br>";
   }
}

$kedi = new Hayvan("Kedi", "Ev");
$kopek = new Hayvan("Köpek", "Bahçe");

$kedi->getInfo();
$kopek->getInfo();
```

Bu örnekte, "Hayvan" sınıfı oluşturuluyor ve "\_\_construct()" yöntemi kullanılarak hayvanların ismi ve yaşam alanı tanımlanıyor. "$kedi" ve "$kopek" değişkenleri, "Hayvan" sınıfından oluşturulan örneklerdir ve "\_\_construct()" yöntemi aracılığıyla belirtilen özelliklere sahiptir. Son olarak, "getInfo()" yöntemi kullanılarak her hayvanın bilgileri ekrana yazdırılıyor.

Kurucu yöntemler, nesnelerin doğru şekilde oluşturulmasını ve özelliklerinin tanımlanmasını sağlayarak sınıfların daha organize ve yönetilebilir olmasına yardımcı olur.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://docs.layraweb.com.tr/merhaba/php-tarafi/konular/siniflar-ve-nesneler/kurucu-yontemler.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.
