NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Possible to display private members in Code Completion?


Joined: 13 Feb 2008
Posts: 32
Reply with quote
Is there a setting to allow the display (in code completion) of private members in objects?
View user's profileFind all posts by linchatSend private message
Guru master

Joined: 05 Jul 2004
Posts: 659
Location: Belgium
Reply with quote
They should be displayed when you can actually access them in the context you are currently in.
View user's profileFind all posts by BlizzSend private messageVisit poster's website


Joined: 13 Feb 2008
Posts: 32
Reply with quote
Only public members are displaying. If I am typing out an object reference

$test->(the autocomplete window should show up at this point)

Only public items are being displayed.
View user's profileFind all posts by linchatSend private message


Joined: 13 Feb 2008
Posts: 32
Reply with quote
Example:

class frank
{
private $dog;
public $animal;
}
$me = new frank();
$me->(the context window will only display animal)

Need to see $dog to.
View user's profileFind all posts by linchatSend private message


Joined: 18 Sep 2007
Posts: 54
Location: Croatia
Reply with quote
Well you set $dog as public, that's the whole point of property scope ain't it?
View user's profileFind all posts by konixnetSend private messageVisit poster's website
Guru master

Joined: 05 Jul 2004
Posts: 659
Location: Belgium
Reply with quote
As i said, the private members only show up if you can actually access them from that place in your code.
If you were to define a function within the class and would try the code insight then the private members are included.
View user's profileFind all posts by BlizzSend private messageVisit poster's website
Veteran

Joined: 06 Mar 2007
Posts: 158
Location: Poland
Reply with quote
Linchat: code completion works at this point very well.

class frank
{
private $dog;
public $animal;
function Test()
{
$this->[code completion shows both dog and animal]
}
}

$f = new frank();
$f->[you will see only Test and animal - a dog is private, schould not be called here, right?]

_________________
ML
View user's profileFind all posts by introSend private messageVisit poster's website


Joined: 13 Feb 2008
Posts: 32
Reply with quote
My problem is I am trying to work around some limitations. Some IDE's will allow you to configure object and there accessors through PHPDOC @property. I would like to do this so I do NOT have to get into the whole __get __set mess of objects. But using PHPDOC I do not have to remember every properties name I was access to.

Example


Code:

class
{
     /*
      * @property $a
      */
     protected $mA;
     protected $mB;

     function _get($func)
     {
     }     

     function _set($func, $val)
     {
           $func = "m".$func;
           $this->$func($val);
     }
}

In this example code, autocomplete will give me NO PREVIEW of what is inside the class due to the protected nature of the properties. So I am in effect blind as the devloper, unless I go back and open the class and so on and so on, autocomplete is defeated. PHPDOC @property tag was created just for interceptors _get, _set, but PHPED does not support it. I am looking for a work around.
View user's profileFind all posts by linchatSend private message
Veteran

Joined: 06 Mar 2007
Posts: 158
Location: Poland
Reply with quote
I think noone schould be able to access private members outside the class. That is really good point here.

But if You do not member Your members, maby You could check "Code Explorer" ?
There You have of course list of all project's classes, methods, members and more.

_________________
ML
View user's profileFind all posts by introSend private messageVisit poster's website


Joined: 21 Mar 2008
Posts: 8
Reply with quote
If I understand correctly, You want to have code completion working for variables accessed only by getters/setters? If its true, then do the following trick

Code:

class test
{
// its public, so code completion works, but can be changed ONLY by setter and not directly
public $someVar;

// the real variable containing value of $someVar as set by setter
private $someVarReal;

public function __construct() {
// deletes entire variable, so only getters and setters will be able to emulate it
unset ($this->someVar);
}

public function __get($key) {
echo "getting '$key' value...<br>";
$key.="Real";
return $this->{$key};
}

public function __set($key, $val) {
echo "setting '$key' value...<br>";
$this->{$key} = $val;
}
}
View user's profileFind all posts by aargothSend private message


Joined: 13 Feb 2008
Posts: 32
Reply with quote
Thanks, I am going to try that. Here is something of what I would like to achieve. Seems like IDE's should have some capability to do this, but none of them do. Basically it allows the "Universal Access Principle"


Code:


An example:
class car {
    /**
    * @Desc here is a list of accessors items that will show up in autocomplete. PHPDOC uses the @property function but does not specify for use with IDE's,
    *              Only that it is an informational source.
    * @property string $Color Color of car (This string shows up in autocomplete)
    */
    protected $mColor;

    function __get($func)
    {
       $func = 'm'.$func;
       return $this->$func;
    }

    function __set($func, $val)
    {
       $func = 'set'.$func;
       $this->$func($val);
    }

    private setColor($val)
    {
       $this->mColor = $val;
    }
}

So in this example, the code is somewhat universal in calls;

$car = new $objCar;
$car->Color = "blue"; ## Here is where some sort of manipulation is needed of autocomplete so "Color" will shop up
print $car->Color; ## Here is where some sort of manipulation is needed of autocomplete so "Color" will shop up

View user's profileFind all posts by linchatSend private message


Joined: 13 Feb 2008
Posts: 32
Reply with quote
That solution worked, I mad a minor revision to your code. You have to UNSET the public variable when every you SET the protected variable. __SET does not work the second time around because the varialbe now exists after being set. The constructor fixes it the first time, not the second. But good solution. Though adds some extra weight to the code, I think it is better then the alternative for now. Hundred of getXXX setXXX functions.

Hopefull NuSphere will jump in on this, take the lead and beat the rest of the IDE's to this.

Here is my addendum:

Code:
<?php
class test
{
   // its public, so code completion works, but can be changed ONLY by setter and not directly
   public $someVar;

   // the real variable containing value of $someVar as set by setter
   private $someVarReal;

   public function __construct() {
      
      // deletes entire variable, so only getters and setters will be able to emulate it
      unset ($this->someVar);
   }

   public function __get($key) {
      echo "getting '$key' value...<br>";
      $key.="Real";
      return $this->{$key};
   }

   public function __set($key, $val) {
      $newKey = $key."Real";
      $oldKey = $key;
      echo "setting new '$newKey' value...<br>";
      print "NEW KEY {$newKey} Value {$val}";
      $this->{$newKey} = $val;
      unset($this->{$oldKey});
   }


$frank = new test();
$frank->someVar = '22';
$frank->someVar = '24';
$frank->someVar = '25';

print "\n<br>".$frank->someVar;
?>
View user's profileFind all posts by linchatSend private message
Possible to display private members in Code Completion?
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic