-4

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.

SINGH
  • 397
  • 1
  • 4
  • 16
  • 2
    In PHP, there's a one byte difference in memory usage per modifier between public and protected/private, but why are you worrying about that? There purpose is visibility, pure and simple – Mark Baker Jan 29 '15 at 08:18
  • 2
    They are called access modifiers for a reason. – sarveshseri Jan 29 '15 at 08:18
  • 2
    Why is this tagged Java? – user253751 Jan 29 '15 at 08:24
  • @immibis - possibly because java has access modifiers too! – Mark Baker Jan 29 '15 at 08:25
  • @mark thanks, is visibility for only from one class to another.?bcz end user never access our php code....Even not clear – SINGH Jan 30 '15 at 15:48
  • Visibility is all about scope within the classes that make up your script, not about what a user can see when executing a script through their browser – Mark Baker Jan 30 '15 at 15:51
  • So why has this been flagged as "opinion-based"? It is a fact that access modifiers have no effect on memory usage in PHP and that fact answers the question. To me it just seems like the question is trivial, not "opinion-based". – Atsby Jan 31 '15 at 03:46

1 Answers1

0

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.

Atsby
  • 2,277
  • 12
  • 14
  • thanks..@Atsby.So is it means only visibility is the main reason to use access modifiers..? – SINGH Jan 30 '15 at 15:51