PHP sınıfı değişken tanımı gerekli mi?

0 Cevap php

PHP Nesne yönelimli programlama yeni Im ama ben usul şekilde kod biliyorum.

Bu benim PHP sınıfı ise

<?php
class person {
  var $name;
  function __construct($persons_name) {
   $this->name = $persons_name;
  }

  function get_name() {
     return $this->name;
  }
}
?>

ve benim PHP sayfa erişmek eğer

$jane = new person("Jane Doe");
echo "Her name is : ".$jane->get_name();

Question: Is it really necessary to put the var $name; in my PHP class since I can correctly get an output of Her name is : Jane Doe even without the var $name; in my PHP class?

0 Cevap