9 Replies Last post: Feb 11, 2013 12:10 AM by Andriy Bazanov  
Newbie Newbie 11 posts since
Jul 6, 2012
Currently Being Moderated

Feb 10, 2013 4:14 AM

"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?

Andriy Bazanov Master 2,652 posts since
May 28, 2010
Currently Being Moderated
Feb 10, 2013 3:27 PM in response to: Newbie
Re: "Undefined function" errors for functions in an included file

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)..

Andriy Bazanov Master 2,652 posts since
May 28, 2010
Currently Being Moderated
Feb 10, 2013 6:42 PM in response to: Newbie
Re: "Undefined function" errors for functions in an included file

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"

Andriy Bazanov Master 2,652 posts since
May 28, 2010
Currently Being Moderated
Feb 10, 2013 7:12 PM in response to: Newbie
Re: "Undefined function" errors for functions in an included file

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 ?

Andriy Bazanov Master 2,652 posts since
May 28, 2010
Currently Being Moderated
Feb 10, 2013 7:16 PM in response to: Newbie
Re: "Undefined function" errors for functions in an included file

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)?

Andriy Bazanov Master 2,652 posts since
May 28, 2010
Currently Being Moderated
Feb 11, 2013 12:10 AM in response to: Newbie
Re: "Undefined function" errors for functions in an included file
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

More Like This

  • Retrieving data ...