 |
 | Possible to display private members in Code Completion? |  |
 |
 | |  |
 |
 | |  |
 |
 | |  |
 |
 | |  |
 |
 | |  |
 |
 | |  |
 |
 | |  |
Joined: 13 Feb 2008 |
Posts: 32 |
|
|
 |
Posted: Wed May 28, 2008 6:31 am |
|
 |
 |
 |
 |
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
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. |
|
|
 |
 | |  |
 |
 | |  |
 |
 | |  |
 |
 | |  |
Joined: 13 Feb 2008 |
Posts: 32 |
|
|
 |
Posted: Wed May 28, 2008 11:52 am |
|
 |
 |
 |
 |
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:
<?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;
?>
|
|
|
 |
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
|
|
|
|  |