What is the difference between access modifiers in

2019-01-27 11:43发布

I am totally confused with access modifiers in php. Is there any difference regarding memory utilization for access modifiers or only difference of accessibility..Please suggest. If i have following code:

public Class Employee {
 public $emp_name='xyz';
 protected $emp_phone='1234567891';
 private $emp_code='101';
 public function getName($name) {
  return 'Employee name is :' . $name;
 }
 protected function getPhone($ph) {
  return 'Employee contact number is :' . $ph;
 }
 private function getCode($id) {
  return 'Employee code is :' . $id;
 }
 $emp = new Employee();
 $emp->getName($emp_name);
 $emp->getPhone($emp_phone);
 $emp->getName($id);
}

Now could any one tell me that how much memory will above variable or function took place.

1条回答
看我几分像从前
2楼-- · 2019-01-27 12:24

No, access modifiers have no effect on runtime memory utilization in either Java or PHP, nor in any other language I have heard of.

Possibly the code size may increase a few bytes due to access modifiers in some bytecodes depending on how they are encoded. Your program must be extremently efficient in other respects before it is worth worrying about this.

查看更多
登录 后发表回答