Using private and public in Classes : private « Class « PHP






Using private and public in Classes

 
<?php
     class myPHP5Class {
          private $my_variable;
          public function my_method($param) {
               echo "my_method($param)!\n";
               echo "my variable is: ";
               echo "{$this->my_variable}\n";
          }
     }

     $myobject = new myPHP5Class();

     $myobject->my_method("MyParam");

     $myobject->my_variable = 10;
?>
  
  








Related examples in the same category

1.class member variable access: private
2.Access private properties with for each loop
3.Changing the member $a to protected or private
4.If the variable was defined as private static, it would not be possible to access it directly
5.Private and inheritance
6.Private properties are accessible only inside the methods of the class that defined them
7.Protect the class from being misused by accessing the members directly