NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Vardoc for $this inside view file

Joined: 30 May 2006
Posts: 35
Reply with quote
dmitri wrote:
For $this it is a lot harder, but the parser in the IDE knows which class does the function call normally right?

No. It does not.
$this can be an instance of the method's class or any of the successors:

class AAA {
   function BBB() {
      return $this;

class CCC extends AAA {   

$c = new CCC();

$a = new AAA();


I have the same problem - how does PHPEd recognize $this via vardoc @var parameter?

Lots of frameworks will only include some view file, so "$this" construct is not defined within the view file.
However, the view file is always created by a controller.

So how can I tell inside view file, that "$this" should map to e.g. AdminController?

This is syntax used by Netbeans:
/* @var $this AdminController */

I tried
* @var $this AdminController

* @var AdminController

but neither of this works in NUSphere..

Can anybody give a clue on this?

Thanx in advance.
View user's profileFind all posts by lubosdzSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 7857
Reply with quote
Indeed, $this is handled as a special case, the case with known class -- the class in the scope.
In the hand, I see no reason why PHPDOC would be ignored for $this, so we'll implement this in 6112 and the following declaration will work starting with this build:

* @var AdminController

Please note, that even though you can call succeessor code by "overriding" or casting class of $this, it certainly violates OOP practice.
For example, suppose we have a class A and another class B inherited from A. If you write a method in class B, you can call any other method in B and in A. This is okay. But you can not and should not call any method of B in A's method. Same goes to the properties.
These rules are followed automatically by PhpED code completion. With this case it will allow calling A and B from B, and won't list B's methods while coding A. You don't need any PHPDOC typehints to make it working in this way.

The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Code Insight challenge for PHP5.3
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 2 of 2  

 Reply to topic