NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Code completion with different scope


Joined: 16 Oct 2006
Posts: 6
Reply with quote
My situation:

I've got 3 directories:
/site/www
/site/actions
/site/classes

The www has got 1 file: site.php; which includes classes/engine.class.php

This engine class creates some other classes, like user and template.
Furthermore, the engine includes one action (choice based on post/getvars) from the actions directory.

I want to edit the login action, and get Code Completion on the template class;
If I type "template::" I get code completion; but if I type "$this->template->" it doesn't know it, because it doesn't know that "this" is the "engine" class.

Is there a way to set this? Or a work around?


(4.6.1; build 4625eval)
View user's profileFind all posts by NielszSend private message


Joined: 05 Jan 2005
Posts: 16
Location: Austria
Reply with quote
I think you just have to properly tag the template member variable with phpdoc comments.
View user's profileFind all posts by matSend private messageVisit poster's website


Joined: 16 Oct 2006
Posts: 6
Reply with quote
mat wrote:
I think you just have to properly tag the template member variable with phpdoc comments.


I doubt that. The editor doesn't even know i'm in the engine scope, so tagging the template member in the engine object won't work.
View user's profileFind all posts by NielszSend private message


Joined: 05 Jan 2005
Posts: 16
Location: Austria
Reply with quote
ahh.. seems like you are creating your action object dynamically. could you post some (pseudo-)code?
View user's profileFind all posts by matSend private messageVisit poster's website
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
To Nielsz:
Quote:
I want to edit the login action, and get Code Completion on the template class;
If I type "template::" I get code completion; but if I type "$this->template->" it doesn't know it, because it doesn't know that "this" is the "engine" class.

Make sure all the directories with your php source files are either in the project tree (in or below project's root directory) or they are listed in the Code Insight Includes list (see project properties). It's sufficient to list only top directories in this list, they are scanned recursively.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 16 Oct 2006
Posts: 6
Reply with quote
a quick example of my code:

site.php?action=login
Code:

$engine = new engine();
$engine->parse($_REQUEST['action']);




engine.class:
Code:

$this->template = new smarty();

function parse($action) {
  include("../actions/".$action.".action.php);
}


login.action.php:
Code:

 #login action; if no data is posted, display login screen;
  $this->template->getContent("login.tmpl");

  engine:: // code completion works; so it knows the engine object
  template:: // code completion works; so it knows the template object
  $this-> // code completion doesn't work, it doesn't know what "this" is.


In login.action.php, I now have the "this" object, which is the engine object.
But if I type "$this->" and try to complete it, the message: "
Code completion is not available due to the following error(s):
Failed to identify type of "$this" global variable
"


So, the problem is not that the files are not in my Code Insight Include List.
View user's profileFind all posts by NielszSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
Quote:
$this-> // code completion doesn't work, it doesn't know what "this" is

If at that point $this contains an instance of specific class, you can put PHPDOC comment about it (see post about type hints on FAQ forum).
If you can't point to a specific class, it means that your code is too dynamic and even you do not know the class name, needless to say that Code Insight can't guess it too Smile

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 16 Oct 2006
Posts: 6
Reply with quote
Ok, that solves half!
Thanks.

in my actionfile I have set this:
Code:

    /**
    * @var engine
    */       
    $this->void();


In my engine class I have documented customer and factory:
Code:

   /**
   * @var customer
   */             
    public
        $customer;     
               
   /**
   * @var objectfactory
   */    
   public
      $factory;



Code:


$c = $this->factory->getCustomerById(); // CC works for the factoryclass;
$this->customer-> // CC works for the customerclass;


$a = $this->customer;
$a-> // CC doesn't work. [i]Failed to find class of "factory" member, declared as "factory")[/i]


Strange, because I declared the factory member as objectfactory.
View user's profileFind all posts by NielszSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
I tried to reproduce the problem but it constantly works well Smile
Look at this:



Would be nice if you compose a sample that replicates the problem you encountered.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 16 Oct 2006
Posts: 6
Reply with quote
nuspheretext.php
Code:

<?

class engine {
    /**
   * @var customer
   */   
   public $customer;
   
    /**
   * @var objectfactory
   */   
   public $factory;
   


    function __construct() {
        $this->factory = new objectfactory();
        $this->customer = $this->factory->getCustomer("waa?");
    }   
   
    function parse() {
        #$this->customer-> //CC Works
        #$x = $this->customer-> // CC Works
        $x = $this->customer;
        #$x-> // CC Works
        $result = include("nuspheretestaction.php");
    }
   
}


class objectfactory {
    function getCustomer($name) {
        return new customer($name);
    }   
}

class customer {
    public $name;
    function __construct($name) {
        $this->name = $name;
    }
 
    function getName() {
        return $this->name;   
    }
   
}

$engine = new engine();
echo $engine->customer->getName();
$engine->parse();

?>

nuspheretestaction.php
Code:

    /**
   * @var engine
   */   
   echo $this->customer->getName(); // CC Works

   $x = $this->customer;
   $x-> // CC Doesnt work


In Nuspheretest.php in the $engine->parse method, all works perfect, but in nuspheretestaction.php, the same doesn't work.
View user's profileFind all posts by NielszSend private message


Joined: 16 Oct 2006
Posts: 6
Reply with quote
Hi Dmitri,
were you able to reproduce it?
View user's profileFind all posts by NielszSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
Hi Nielsz,
yes, sure, I was able to get it. Now it needs our developer's time to get fixed Smile

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Code completion with different scope
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 2  

  
  
 Reply to topic