0

I have 2 classes:

class MyClass1
{
   private $private1 = 'Private1';
   private $private2 = 'Private2';
   private $private3 = 'Private3';

   function printHello()
   {
       echo $this->private1;
       echo $this->private2;
       echo $this->private3;
    }
}

class MyClass2
{
   public $private1 = 'Private1';
   public $private2 = 'Private2';
   public $private3 = 'Private3';

   function printHello()
   {
       echo $this->private1;
       echo $this->private2;
       echo $this->private3;
    }
}

How about memory usage if running these classes? Running MyClass1 uses less memory than Myclass2? Please, note that I ONLY ask about memory usage.

duyvu1311
  • 97
  • 2
  • 11

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.

from this answer

Community
  • 1
  • 1
RobinF
  • 349
  • 1
  • 2
  • 17