"Undefined function" errors for functions in an included file

I have a PHP file, call it test.php, outside of my www folder and am including it like the following in a number of files:

require_once( __DIR__ . '/../../test.php');


When I had test.php inside of the www folder, everything was fine, but after I moved it outside of the www folder PhpStorm now highlights all of the functions in the file and gives the error "Undefined function ..."

If I click on "test.php" in the above line of code, PhpStorm opens that file, so clearly PhpStorm knows the file exists. Since PhpStorm can jump to the file when I middle click it, I don't understand why it doesn't recognize that the functions in the file exist?

9 comments

Hi there,

Is this file is inside your project .. or outside?

Yes, PhpStorm can open any file in any location (even windows/linux/macos system file), but that does not mean that it will be indexing it if it is not included in project in any way (External Library, Content Root or whatever)..

0

Thanks for your quick reply.

The file shows up in the project pane in the workspace, does that mean it is included in the project?

0

Yes, if file is shown in Project View panel, then it is included.

1) Does that file has php icon .. or some another?

2) Maybe that file (or functions with such name) got included more than once?

3) When you Ctrl+Click on such "udefined" function, what PhpStorm tell you?

4) Please try "File | Invalidate caches"

0

Hi, thanks again for your help.

1) Yes, it has the php icon like the other php files

2) I don't believe so. If I move the file down a directory into the www folder and then change the include path to reflect the new location, the problem goes away

3) "Cannot find declaration to go to"

4) I just tried this and unfortunately the problem still exists

0

Luckily I stumbled across the solution. I went to:

File->Settings->Directories

Then changed the Content Root from my www directory to the one above it. So while my test.php file (that I was including) showed up in the directory pane, it must not have really been "included" in the project, per se?

Anyways, it's fixed!

0

I cannot say what is going on based on description alone, unfortunately.

Can you reproduce it somehow in empty brand new project (like, same folder structure, that file (can be function declarations only -- empty function body) and some file(s) that uses those functions) ? This will be the best.

Maybe you have configured "unresolved include" inspection somehow too tight.. and that inspection fails ..., dunno ?

0

So .. how it was visible in Project View panel in such case?

If file is not in one of the Content Roots, not part of the External Libraries (Settings | PHP | Include paths) .. then it should not be shown in Project View panel (unless you have sumlink to it from another location within project).

I know -- issue is solved for you -- but if you have time, could you post some screenshots with your folder structure and configuration (what folders are incuded etc)?

0

I don't see any php include paths under (Settings | PHP | Include paths).



Playing around with this some more, I think maybe the "test.php" file wasn't actually in the project; it showed up in the project pane, but it wasn't in the project tree in the project pane, if that makes sense. After making the Content Root one directory higher, the "test.php" file still shows up under the project pane, but now it is in the project tree.

If that behavior is not correct I can send you some screenshots, but because this is for a business website I'd prefer to not post them on the forum.

0
I don't see any php include paths under (Settings | PHP | Include paths).

screen01.png

Playing around with this some more, I think maybe the "test.php" file wasn't actually in the project; it showed up in the project pane, but it wasn't in the project tree in the project pane, if that makes sense.

Hmm .. not really. I need to see some screenshot to understand this.

You can post screenshot here -- just blur/hide private stuff (like sitename or whatever) -- noone really cares about someone else's folder structure / file names. Let me know

0

Please sign in to leave a comment.