NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Code Completion for Included Class Files


Joined: 04 Jun 2004
Posts: 9
Reply with quote
I don't know if I changed a setting accidently, or if it was never working this way to begin with and I'm smoking crack.

My project is laid out like this.

Code:

Project Root\
  index.php
  class\
     class.php
     class2.php
  modules\
      module1\
          module1.php
          module1-2.php
      module2\
           module2.php


Index.php includes files based on various options from the modules directory. So if index.php includes module1.php, in module.php I would include any needed classes relative to index.php's position in the project, and not it's self.

So in essence I would have something like this...

Code:

<?PHP
// index.php

include('modules/module1/module1.php');

?>


In module1.php, any classes needed would be included as such.

Code:

<?PHP
// module1.php

include('class/class.php');
include('class/class2.php');

$obj = new MyClass;

?>


I've only been using PHPEd for about a week now, but it seems to me that if I was working in module1.php, code insite would work correctly on an object invoked from a class, even if the included class definition directory was not relative the its position in the file, because it was included in the project.

However this seems to have quit working, or like I said, maybe I was just smoking crack. Does any body know if I messed up a setting some where or if this is working as intended?
View user's profileFind all posts by lagsalotSend private messageYahoo Messenger


Joined: 04 Jun 2004
Posts: 9
Reply with quote
And I forgot to include..

WinXP Pro
PhpED 3.3.1 (Build 3356eval)

Eval as my company is dragging its feet with the purchase order.
View user's profileFind all posts by lagsalotSend private messageYahoo Messenger
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
Seems a little problem is there. To make sure what base directory the relative path should be calculated from, IDE should distinguish scripts that can be called using URL from included files that can't be. With current implementation, PHPED takes directory of the script where you call include() and adds relative path of the include statement. It works right for the _base_ files (that can be called via URLs) and does not work right for the files that are included from other scripts that are located in different directories...
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 04 Aug 2004
Posts: 13
Reply with quote
Is there any chance this is going to be fixed anytime soon though? I have the same issues, and it's making me go mad...

1. the auto-code completion thing is a real showstopper if it doesn't work like lagsalot described it (I acually have the exact same structure, which is I believe a very common one Wink )

2. Also when debugging, the include is always working from the current position..

For instance, take the following example:

index.php
/includes/genericfunctions.inc.php
/includes/securityfunctions.inc.php

What i do in index.php is include /includes/genericfunctions.inc.php and then call the initialising function that should do the rest.
In that initialiser, I want to include the securityfunctions.inc.php, so I do include_once('includes/securityfunctions.inc.php') which is correct, as the script is being executed as index.php - yet, phpED seems to be searching for /includes/includes/securityfunctions.inc.php in stead...

I hope this can be helped soon though Smile This may get me to renew my licenses Smile
View user's profileFind all posts by speedpacketSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
Code completion is supposed to work even if nothing is really executed. How would PhpED know what is the so called "current position" Smile
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 04 Aug 2004
Posts: 13
Reply with quote
ddmitrie wrote:
Code completion is supposed to work even if nothing is really executed. How would PhpED know what is the so called "current position" Smile


AS far as I can tell, code completion is only there for functions within the file you are editing, or files that you actually included using include() or include_once()...

Regarding your feedback - I'm executing index.php in the root, so it's obvious that all includes should be starting from that location, as this is what PHP does...

I'm not sure you're following what I'm trying to say, but then again it might be my English Smile Please let me know if you don't really understand what I'm referring to, and I'll try and explain better...
View user's profileFind all posts by speedpacketSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
Quote:
AS far as I can tell, code completion is only there for functions within the file you are editing, or files that you actually included using include() or include_once()...

Not exactly Smile Let me demonstrate it.

what's about the following?

file a.php:

Code:
<?php
  function fun_a() {
  }
  include "b.php";
?>



file b.php:

Code:
<?php
 // you're typing here below:
?>


should function fun_a() be shown in code completion if you're in b.php ?
From the php's perspectives it should.
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 04 Aug 2004
Posts: 13
Reply with quote
No, but this is not what I'm referring to...

file a.php:

Code:
<?php
  include_once("b.php");
 
  fun_c();
?>


file b.php:

Code:
<?php
  include_once("c.php");
?>


file c.php:

Code:
<?php
  function fun_c() {
  }
?>


in the above, code completion will not work when trying to caal fun_c() from within file a.php because it is third level inclusion... if I had a function in file b.php, it does it perfectly well...

The second issue I'm talking about:

file index.php:
Code:
<?php
  include_once("includes/genericFunctions.inc.php");
?>


file includes/genericFunctions.inc.php:

Code:
<?php
  include_once("includes/securityFunctions.inc.php");
?>


-> this will crash in debug, as it is searching for includes/securityFunctions.inc.php based on the location of the includes/genericFunctions.inc.php file; meaning it will go look for includes/includes/securityFunctions.inc.php, where it should actually, from a php perspective, search based on the location of the file that is actually being executed, in this example being index.php, and should include the file starting from that location in the directory tree...

I hope this all makes sense now...
View user's profileFind all posts by speedpacketSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
Quote:
-> this will crash in debug

What do you mean Question
Quote:
as it is searching for includes/securityFunctions.inc.php based on the location of the includes/genericFunctions.inc.php file

Who? Debugger? Code Insight Engine?

Quote:
meaning it will go look for includes/includes/securityFunctions.inc.php, where it should actually, from a php perspective, search based on the location of the file that is actually being executed, in this example being index.php, and should include the file starting from that location in the directory tree...


If you mean Code Insight, please tell me how would it guess what file is being executed when you're just typing your code?
If you mean Debugger, it does never seach for anything. Php engine does and always follows its rules.
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 04 Aug 2004
Posts: 13
Reply with quote
ddmitrie,

I'm having the feeling that you don't want to understand what I'm telling you. I don't know how I can get this any more clearer to you...

I'm talking about utomatic code completion, so Code Insight Engine...

It could easily "guess" what file is being executed by having a setting that says what is the root handler file that will call all other files in the project. I believe our setup is very common where we have ONE index.php that is ALWAYS being called when we execute anything withing the project, as this allows us to do general stuff there (such as user authentication, security checkings, license checkings, initialisation of database settings, and more...)

I do understand what you're saying, but I really don't know what is so incomprehensible about my explanation...
View user's profileFind all posts by speedpacketSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
Quote:
I believe our setup is very common where we have ONE index.php that is ALWAYS being called

Personally, I'm not sure why index.php would be considered as a root file to call for all the other project files. For example, in PHPBB you're reading right now there are many such "root" files, namely posting.php, index.php, viewforum.php, search.php, memberlist.php, faq.php, profile.php and many many other files.

Quote:
I really don't know what is so incomprehensible about my explanation

Actually, I didn't mean that. You explained what you want and I tried to explain why it's not so easy in Phped 3.3.
On the other hand, PHPED 4.0 will come with different approach. It captures all the project files, classes, functions, methods etc etc etc and show you codecompletion without much problems with settings and directories the files are located in.
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 12 Feb 2005
Posts: 48
Reply with quote
Dmitrie

Speedpacket is using a development method (aka Design Pattern) known as the MVC - Its been used for years in the Java market and has become the defacto standard for designing J2EE powered sites, and now its become increasingly more popular with PHP.

http://www.phppatterns.com/docs/design/archive/model_view_controller_pattern

Cheers
View user's profileFind all posts by KelvinSend private message
Code Completion for Included Class Files
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