 |
 | [resolved] open file at cursor |  |
Joined: 15 Aug 2006 |
Posts: 21 |
|
|
 |
Posted: Thu Jun 07, 2007 9:02 am |
|
 |
 |
 |
 |
I have this code:
require_once 'D:\libs\file.php';
|
Sequences \l & \f in string means l & f, because this is single quoted string. But when I press right mouse button and try "Open file at cursor", PHPEd tries to open file "D:\ile.phphp".
|
|
Site Admin
Joined: 13 Jul 2003 |
Posts: 8355 |
|
|
 |
Posted: Wed Jun 13, 2007 9:09 am |
|
 |
 |
 |
 |
Quote: | Sequences \l & \f in string means l & f, because this is single quoted string |
and your path becomes D:libsfile.php
which is what PhpED can't open.
Either use / or double slashes like below:
require_once 'D:/libs/file.php';
require_once 'D:\\libs\\file.php';
|
_________________ The PHP IDE team
|
Veteran
Joined: 06 Jun 2007 |
Posts: 289 |
Location: Vancouver, Canada |
|
 |
Posted: Wed Jun 13, 2007 12:28 pm |
|
 |
 |
 |
 |
In PHP, one needs to use double quoted stings when escaping characters. In other words, the following variations are valid:
require_once 'D:\libs\file.php';
require_once "D:\\libs\\file.php";
|
and these are not valid
require_once 'D:\\libs\\file.php';
require_once "D:\libs\file.php";
|
I think it would be more intuitive if PhpED followed PHP's example 
|
|
 | require file |  |
 |
 | |  |
 |
 | |  |
Joined: 22 May 2004 |
Posts: 76 |
|
|
 |
Posted: Tue Jun 19, 2007 3:23 pm |
|
 |
 |
 |
 |
dmitri wrote: | Quote: | <?php
require_once('noname1.php');
?> |
Why do you believe that this call will include noname1.php from current directory?
It's just a wrong assumption
Say you have A.php in the root directory and this file includes B.php that is in "lib" subrirectory. If B.php includes C.php and does so without path, php will look for C in the root because it's where A is. Please read PHP rules for included files. |
I dont know what the rules of php are saying on this matter, but I do know that php has always and still calls to the the most relative file. If the calling file is in the same directory as the required file, then unless an absolute path is specified, it looks for the file within the immediate directory of the calling file. Now if the rules of php specify something different then this, then they do not reflect the way php works. When I run noname2.php on the linux server, it calls to noname1.php which is located in the immediate directory and not to the one located in the root.
Now it is the same for other scripts too.
Consider this:
I create two directories located in /root
/root/1/
- 1_1.php
/root/2/
- 1_1.php
- 1_2.php
In 1_2.php from /root/2/ I add the line: require_once('1_1.php'); then i right click to open at cursor
But phped doesnt open 1_1.php located in the directory /root/2/ even though that is where the calling file is located and the target file.
Instead it opens the file (1_1.php) from the directory (1/)
But run this same example on the server and php will open the file 1_1.php as it is located in the directory /root/2/ i.e., the same directory where the calling file is located.
Jeff
|
|
 |
 | |  |
Joined: 14 Jun 2007 |
Posts: 67 |
|
|
 |
Posted: Tue Jun 19, 2007 5:42 pm |
|
 |
 |
 |
 |
jphilapy wrote: | I dont know what the rules of php are saying on this matter, but I do know that php has always and still calls to the the most relative file. If the calling file is in the same directory as the required file, then unless an absolute path is specified, it looks for the file within the immediate directory of the calling file. Now if the rules of php specify something different then this, then they do not reflect the way php works. When I run noname2.php on the linux server, it calls to noname1.php which is located in the immediate directory and not to the one located in the root. |
I think the rules Dmitri is referring to is the PHP include search rules. By default, PHP will search in the current working directory (I think the directory where script started in) then in the include directories.
But, you can change the working directory by using chdir() in you PHP script. So, assuming where an include is located may not work.
Cameron.
|
|
 |
 | |  |
Site Admin
Joined: 13 Jul 2003 |
Posts: 8355 |
|
|
 |
Posted: Wed Jun 20, 2007 9:22 am |
|
 |
 |
 |
 |
Right, I referred to php rules that php uses for include/require statements:
Quote: | Files for including are first looked in include_path relative to the current working directory and then in the directory of the current script. E.g. if your include_path is libraries, current working directory is /www/, you included include/a.php and there is include "b.php" in that file, b.php is first looked in /www/libraries/ and then in /www/include/. If filename begins with ./ or ../, it is looked only in include_path relative to the current working directory. |
As a bottom line, from the IDE perspectives, it does not know "current directory".
Say we're in B.php that includes C.php. But B.php itself is included from A.php and what you call in your url is A.php.
Current directory will be A's directory. But B.php does not know it  and what relative path you use in the include statement in B.php, will be appended to A's path. Subsequently if you include B.php in A2.php, it will use A2's path... Needless to say that IDE does not know what files you will run as the 1st level files and therefore it does not know how to use relative path it sees in the include(). That's why we added INCLUDE tab in the project properties. Please make sure you have all include() statements properly resolved there.
|
_________________ The PHP IDE team
|
 |
 | |  |
Joined: 22 May 2004 |
Posts: 76 |
|
|
 |
Posted: Wed Jun 20, 2007 11:24 am |
|
 |
 |
 |
 |
dmitri wrote: | Right, I referred to php rules that php uses for include/require statements:
Quote: | Files for including are first looked in include_path relative to the current working directory and then in the directory of the current script. E.g. if your include_path is libraries, current working directory is /www/, you included include/a.php and there is include "b.php" in that file, b.php is first looked in /www/libraries/ and then in /www/include/. If filename begins with ./ or ../, it is looked only in include_path relative to the current working directory. |
As a bottom line, from the IDE perspectives, it does not know "current directory".
Say we're in B.php that includes C.php. But B.php itself is included from A.php and what you call in your url is A.php.
Current directory will be A's directory. But B.php does not know it and what relative path you use in the include statement in B.php, will be appended to A's path. Subsequently if you include B.php in A2.php, it will use A2's path... Needless to say that IDE does not know what files you will run as the 1st level files and therefore it does not know how to use relative path it sees in the include(). That's why we added INCLUDE tab in the project properties. Please make sure you have all include() statements properly resolved there. |
Dmitri, are you saying that phped is not able to find the file even though php is able to find it? I mean is it your intention that phped look for files differently than php, because im my example that I posted, that is clearly what it is doing.
Jeff
|
|
 |
 | |  |
 |
 | |  |
Joined: 22 May 2004 |
Posts: 76 |
|
|
 |
Posted: Wed Jun 20, 2007 6:33 pm |
|
 |
 |
 |
 |
dmitri wrote: | Jeff,
No PHP IDE in the world know the path that php will use. IDE can only guess the path. There are cases when guessed path matches real life, and there are always cases when can not guess.
PhpED is just an instance of the IDE and therefore conforms the rule above.
You may help it by providing correct path on the INCLUDES tab as I said before. |
All I know is that Dreamweaver's implementation of open file at cursor gets it right so far every time where as phped doesnt. So apparently it is possible for an editor to get it right which is all that matters, unless of course you have some case studies that demonstrate that dreamweaver doesnt get it right. My point is exactly that phped should get it right and can but doesnt. I even used the refresh option provided in the includes section for the project, and it still doesnt get it right. If I have to manually fix each include, then that is counter productive. I can just use dreamweaver to find the file which is far more sensible then manually fixing every include path.
dmitri wrote: |
You're wrong assuming that the relaive path you use in include() is realative from the current file location. It's only the case with files that you call with URL. For the other files, that may not work. It's a weak side of php engine as it was created in the beginning. |
If that is the case then why does php on my server always, not sometimes, call to the immediate file relative to the current location rather than some file located elsewhere? Perhaps I am misunderstanding you but I did some tests and php always grabs the file closest to the calling file except in the instance where you chain the files like in your example, which isnt the case here.
Jeff
|
|
 |
 | |  |
Site Admin
Joined: 13 Jul 2003 |
Posts: 8355 |
|
|
 |
Posted: Wed Jun 20, 2007 7:23 pm |
|
 |
 |
 |
 |
seems this discussion is more about theory than practice. Let's consider the followin simple example. I suppose you know php quite well so you'll guess what path will be printed.
create a.php in the root directory of disc C:\ with the following content:
<?php
include "include/b.php"; |
create directory include in c:\ and create file b.php in it (its full path will be c:\include\b.php) and its content should be:
<?php
include "include/c.php"; |
create one include subdirectory within include and file c.php in it (its full will be c:\include\include\c.php) and its content should be:
<?php
echo __FILE__ . "\n"; |
create a copy of c.php one level upper
then try to run a.php with any php engine you have.
|
_________________ The PHP IDE team
|
 |
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
|
|
|
|  |