What is the difference between access modifiers in php? [closed]

…衆ロ難τιáo~ 提交于 2019-11-28 06:56:25

问题


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:


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.



来源:https://stackoverflow.com/questions/28209887/what-is-the-difference-between-access-modifiers-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!