> 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/miras-inheritance.md).

# Miras (Inheritance)

PHP'de miras, bir sınıfın başka bir sınıftan özelliklerini ve yöntemlerini alabilmesini sağlayan bir özelliktir. Miras, programlama dilinde nesne yönelimli programlama (OOP) prensiplerinden biridir ve sınıf hiyerarşileri oluşturulmasına olanak tanır.

Bir sınıfın başka bir sınıftan miras alabilmesi için `extends` anahtar kelimesi kullanılır. Aşağıda basit bir örnek verilmiştir:

```php
class Person {
   public $name;
   public $age;
   public function __construct($name, $age) {
      $this->name = $name;
      $this->age = $age;
   }
   public function introduce() {
      echo "My name is {$this->name} and I am {$this->age} years old.";
   }
}

class Student extends Person {
   public $studentID;
   public function __construct($name, $age, $studentID) {
      parent::__construct($name, $age);
      $this->studentID = $studentID;
   }
   public function studentInfo() {
      echo "My name is {$this->name}, I am {$this->age} years old, and my student ID is {$this->studentID}.";
   }
}

$student = new Student("John Doe", 20, "1234");
$student->introduce();
echo "<br>";
$student->studentInfo();
```

Bu örnekte, `Person` sınıfı tanımlanmış ve `Student` sınıfı, `Person` sınıfından miras almıştır. `Student` sınıfı, `name` ve `age` özelliklerine erişebilir ve `introduce()` yöntemini kullanabilir. `Student` sınıfı ayrıca kendine özgü bir `$studentID` özelliğine sahiptir ve `studentInfo()` yöntemiyle bu özelliği kullanır.

`parent::__construct()` ifadesi, `Student` sınıfının yapıcı yöntemiyle `Person` sınıfının yapıcı yöntemini çağırır ve `name` ve `age` özelliklerine erişimi sağlar.

Miras, kodun yeniden kullanılmasını ve sınıflar arasındaki ilişkilerin daha iyi anlaşılmasını sağlar. Ancak, kötü tasarlanmış sınıf hiyerarşileri, kodun okunmasını ve bakımını zorlaştırabilir.


---

# 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/miras-inheritance.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.
