How to "hide" private variable in PHP class -


i might not have understanding of this, since "username" variable private. shouldn't not part of return? how make $username private , not outputed, public member is?

class myclass  {     private $username = "api";       public function create_issue()     {         $this->public = "joe";         return $this;     }  }  $test = new myclass(); $test->create_issue();  var_dump($test);  class myclass#1 (2) {   private $username =>   string(3) "api"   public $public =>   string(3) "joe" } 

i have understood concern. first of all, let me discuss variable scope private. private variable private in current class. if use class in class private variable not work. so, have use class protect private variable.

<?php  class myclassprotected  {     private $username = "api";     public function dosomething(){        // write code using private variable    }  }   class myclass {        public function create_issue()      {        $test = new myclassprotected();        $test -> dosomething();        return $this->public = "joe";     } }   $test = new myclass(); $test->create_issue(); var_dump($test);  ?> 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -