NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Code Completion for Class private/protected members/methods


Joined: 16 Jun 2011
Posts: 31
Reply with quote
Hi,

it would be really cool if the code completion for protected/private members/methods would be possible.

Let us say you have magic __get, __set, __call in your classes and you access a protected members directly via it's name.
In this case, NuSphere doesn't auto complete the name of the member. But fortunately the PHPDoc support still works.

Use case where the code completion doesn't work:
Code:

class Test{
    protected $mymember;
    public function __get($name){
        echo $this->{$name};
    }
}
$test = new Test();
echo $test->mymember;
View user's profileFind all posts by brainSend private message
Guru master

Joined: 24 Jul 2009
Posts: 737
Reply with quote
Because mymember is protected, surely it is correct for code completion to not work?

You could make mymember public, then code completion would work.
View user's profileFind all posts by plugnplaySend private message


Joined: 16 Jun 2011
Posts: 31
Reply with quote
In general this is correct but for magic setters/getter, as is mentioned it, it's a bit disturbing.

In PHP you CAN access protected/private members, when you define the magic setters/getters.
But you can't use magic getter/setters for public members. http://www.php.net/manual/en/language.oop5.overloading.php#object.get

Therefore it would be cool to have an option in nusphere settings to allow protected/private member auto completion.
It's really helpful when you have protected/private members that be accessable/writeable through the magic getters/setters.
View user's profileFind all posts by brainSend private message
Guru master

Joined: 24 Jul 2009
Posts: 737
Reply with quote
You mention PHPDoc but do you mean using @method ?

Code:
/**
 *
 * @method Test mymember()
 */
class Test{
    protected $mymember;
    public function __get($name){
        echo $this->{$name};
    }
}
$test = new Test();
echo $test->mymember;


The above works in PhpED plus it also clearly documents that there is a predefined protected/private variable that can be accessed.

If you extend class Test then PhpED does offer mymember in code completion without using @method, because PhpED knows that mymember should be directly accessible:

Code:
class Test{
    protected $mymember;
    public function __get($name){
        echo $this->{$name};
        return $this->{$name};
    }
}

class Test2 extends Test{
    public function getMymember(){
        $x = $this->mymember; // direct access
        $x = $this->mymember(); // through magic __get
        return $x;
    }
}
View user's profileFind all posts by plugnplaySend private message


Joined: 16 Jun 2011
Posts: 31
Reply with quote
First a little note.
The @method works more worse than good because it's handled as a method, which it isn't.

Let me exactly explain why i want the auto completion.

I have this (strongly simplified)
Code:
class DBObject{

    /**
    * Id
    *
    * @var int
    */
    protected $id;

    /**
    * DateTime
    *
    * @var DateTime
    */
    protected $createTime;

    /**
    * Magic Getter
    *
    * @param string $name
    * @return mixed
    */
    public function __get($name){
        return $this->{$name};
    }

    /**
    * Magic Setter
    *
    * @param string $name
    * @param mixed $value
    */
    public function __set($name, $value){
        $this->{$name} = $value;
    }
}

$obj = new DBObject();
$obj->createTime->...


As you can see, "$obj->createTime->" offers you a correct code completion list for the methods and members for the DateTime object (this is what already works fine).
But when i just type "$obj->crea" i want a auto completion to write my code faster.

This way i use is really fast for creating new childs of this class without the need of creating a getter/setter for each member.
A public member instead of protected is not possible in my case because many conversations happens in the magic __get/__set which i've removed in this examplecode.
Please let us not talk about my way of coding, if someone try to.

I just wanted to suggest that it would be helpful for some people, like me, with a auto completion - And i just explain why this would be helpful to give the DEV's a reason to think about.
View user's profileFind all posts by brainSend private message
Guru master

Joined: 24 Jul 2009
Posts: 737
Reply with quote
What about this then?

Code:
/**
 *
 * @property DateTime $mymember
 */
class Test{
    protected $mymember;
    public function __get($name){
        echo $this->{$name};
    }
}
$test = new Test();
echo $test->mymember;
View user's profileFind all posts by plugnplaySend private message


Joined: 16 Jun 2011
Posts: 31
Reply with quote
plugnplay wrote:
What about this then?

That's what i searched for.
Thank you.
View user's profileFind all posts by brainSend private message
Code Completion for Class private/protected members/methods
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