Eclipse autocomplete is not working for PHP-project - php

My Eclipse doesn't use auto-complete... My colleague get a whole list of suggestions by just typing some letters and I get nothing...
The Eclipse version I use is:
Eclipse for PHP Developers
Version: Helios Service Release 2
Build id: 20110301-1815
(c) Copyright Eclipse contributors and others 2000, 2011. All rights reserved.
Visit http://eclipse.org/
And I think I've set all available settings for autocomplete.
I lose a huge amount of time every time I have to search for the correct naming. Is there any module of software I've to install extra to get this autocompletion?

Ok, found the solution! Apparently I had to "Add PHP support" in the properties window of the project. Thanks for all the help though!

Generally this can be activated by enabling Content Assist. It can be found on Window-Preference->PHP->Editor->Content Assist
Setup your php_include_path. Go to the properties of the project. Then PHP Include Path.
If you have any external library add it there too (I use Zend and Kohana).

I did it by deleting ".metadata" directory on my main workspace :D

I can try ALL answers (from this and others threads), only work for me delete (or rename for backup) .metadata folder on workspace folder
Close eclipse
mv .metadata .metadata_older
Start eclipse (clean start wrokspace of eclipse, none project are listed)
Import from workspace your project
Eclipse rebuild and refresh works (several project settings are lost!!!)
Autocompletion, follow code, etc now work.
This isn't the ideal solution, but is the ONLY solution for me, I migrated from eclipse 3.6 to 4.4 in one step, and PHP support is gone, only highlight code are working until delete .metadata folder.
Ubuntu 12.04 LTS 64 Java 1.7 ORACLE
Thanks.

Check the options in Windows preferences for content assist. It might be disabled. It probably would be php -> Editor -> Content Assist and see what is selected for auto activation.

I don't use Eclipse, but I know in Netbeans (and other IDE's) you can type Ctrl + Space to bring up the auto complete window after you start typing a function/variable.
Give that a try.

If this happens only for one project in Eclipse and others are autocompleting correctly, it sometimes happen when you create new PHP project and press Finish on the first page.
To fix it, remove the project from Eclipse (Windows > Show view > Navigator and press DELETE on the project). Then go to project folder and delete file .project and folder .setting.
In Eclipse now select File > New > PHP project, select name and folder, press Next and verify (or manually add) that root folder of the project is listen on Source tab.
Then click Next and add root folder of the project or folders that contain PHP files into Build path. Now you can click Finish.
Note: adding Source and Build paths into existing project usually does not fix this problem and you really have to delete and create new project.

Right click on the project -> Properties -> PHP -> Validation
Check the Enable prockect specific settings
Select PHP Ver

Check your .buildpath, try build something like this:
<?xml version="1.0" encoding="UTF-8"?>
<buildpath>
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
<buildpathentry kind="src" path="src"/>
<buildpathentry kind="src" path="vendor"/>
<buildpathentry external="true" kind="lib" path="common-libs/vendor/project-sample/lib"/>
</buildpath>

Related

Eclipse 2019-06 PHP autocomplete (content-assist) not working

I've juste installed the latest version of Eclipse, Eclipse 2019-06.
Infortunatly, the PHP content-assist or autocomplete doesn't work anymore when working on remote system.
I've searched for solutions but didn't find anything...
The files are on a remote workspace, not local. It was OK with and old version of Eclipse (Mars), there are illustrations above.
I've checked in the preferences at PHP->Editor->Content assist, the Auto-Activation is checked.
Here is an illustration :
https://ibb.co/MD72NKv
With an old version, it worked well :
https://ibb.co/R7xQShL
Thank you in advance !
OK the problem is solved.
It occured only with files on remote system, not on a local file in the workspace.
Thi solution here work perfectly :
https://drupalsun.com/patrick/2011/07/25/how-setup-eclipse-php-pdt-remote-system-explorer-theme-manager-and-drupal-plugins
Now we are going to use RSE to edit an eclipse RSE .project file. So in your 'Remote System' tab open up your local files and navigate to you workspace folder. Look for a folder called 'RemoteSystemsTempFiles' and open that. Now you are going to edit the '.project' file. Open up that file.
You are going to add two line in between the <natures> tag, those lines are
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
<nature>org.eclipse.php.core.PHPNature</nature>
Save that file and restart eclipse. If you did everything correctly you should now have auto complete that will look like so

PhpStorm - all files have blue font (no color coding for methods/properties)

I created a new project using Laravel's command composer create-project --prefer-dist laravel/laravel blog
When I open it in PhpStorm, all the files look like this:
I haven't done anything at all but any file I open has the same color text and when I type anything I get no text suggestions.
Has anyone had this issue before?
P.S. Valet works and I can run the project in localhost.
I'll hazard a guess that somehow your files aren't being associated with PHP. You can reset this in settings by making sure that files ending in .php are recognized by PHPStorm as PHP files:
Image of PHPStorm 2018.1
In settings, go to Editor -> File Types -> PHP and make sure that *.php (or whatever your exotic PHP extension is) is present. Hit Apply.

How to add a custom file extension that has a dot (blade.php) in NetBeans?

I need to assign a custom extension to be recognized as a twig file in netbeans ('blade.php' as 'twig' file and give me syntax highlighting and code completion appropriately). The problem with using the File association option (in Tools > Options > Miscellaneous > Files)
is that it won't let me add '.' in extension like blade.php, it works with single worded extensions like php, html, css etc.
Will be grateful if anybody can help me with this!
Workaround I figured out and seems to work (at least Netbeans 8.x+)
Go to Tools > Options > Miscellaneous > Files
Click New
Enter blade as the new extension (you can use anything here, but this seems the most natural)
Click OK
In Associate File Type (MIME) select TWIG (text/x-twig)
Click OK of the whole Options window
Close Netbeans
Open the Netbeans configuration folder - on Windows it's %AppData%\Netbeans\<version>\
Go to subfolder config\Services\MIMEResolver
Open user-defined-mime-resolver.xml
Find the <ext name="blade"/> entry (or whatever you entred above)
Change the blade to blade.php
Save and close the file
Voilà, higlighting should now work in Netbeans IDE :)
Modify the user-defined-mime-resolver.xml file so that it looks something like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE MIME-resolver PUBLIC "-//NetBeans//DTD MIME Resolver 1.1//EN" "http://www.netbeans.org/dtds/mime-resolver-1_1.dtd">
<MIME-resolver>
<file>
<ext name="php"/>
<name name=".blade" substring="true"/>
<resolver mime="text/x-twig"/>
</file>
<file>
<ext name="php"/>
<resolver mime="text/x-php5"/>
</file>
</MIME-resolver>
On Linux (Ubuntu), you can find this file at:
$HOME/.netbeans/8.2/config/Services/MIMEResolver/user-defined-mime-resolver.xml
On Windows, you can find the file at:
%AppData%\Netbeans\8.2\config\Services\MIMEResolver\user-defined-mime-resolver.xml
Basically, the first <file> block scans the filename of any PHP files to see if it contains the ".blade" substring. If so, the file is treated as a Twig file. If not, the second <file> block will treat the file as a normal PHP file.
You might need the "Twig Templates" NetBeans plugin in order to get proper highlighting:
Tools > Plugins > Available Plugins > Twig Templates
It's not perfect... Blade directives such as #include are still highlighted as plain text. However, I feel it is a marked improvement over PHP syntax highlighting.
The following sources were extremely helpful:
HOW TO: Declarative MIME Type Resolvers
DTD Grammar Documentation
David Benedeki's earlier answer to this question
A lot of people are developing on other systems, as I am on Centos 7, so this workaround almost worked.
For CentOS, and probably other systems as well, follow these steps, almost the same as above for Windows:
Open Netbeans. Go to Tools->Options->Miscellaneous and select tab Files.
In File Extension row, click New button. Enter crazywrongname as extension name (this is important for option 2)
Below that, under Associated File Type (MIME): choose the option TWIG (text/x-twig)
click Apply and then OK.
Close Netbeans
Option 1:
The following steps are for CentOS 7 and NetBeans 8.1, most probably for other systems as well, but if you can't find the file at that path, option 2 is below.
open Terminal and open the file /root/.netbeans/8.1/config/Services/MIMEResolver/user-defined-mime-resolver.xml in your favourite text editor, e.g. run command nano /root/.netbeans/8.1/config/Services/MIMEResolver/user-defined-mime-resolver.xml
find the parameter name "crazywrongname" in this file and change it to "blade.php"
save the file
open Netbeans and enjoy.
People from the future, you might try changing the Netbeans version in file path from option 1 to yours, like 14.3 or whatever is out in 2028.
Option 2:
If you can't find this file in the exact path as above, run this command to find it:
cd / && grep -rI --exclude-dir=proc --exclude-dir=sys crazywrongname *
This will start a search for the specific pattern on your whole system, starting at root. That's why we named the parameter crazywrongname - so it isn't found in any other file on the system, like blade would be. It will also exclude the folders that are not supposed to be accessed. If you don't exclude them, you will get errors and possibly hang your system. Also, some pink unicorns might die.
After you find the exact file path for your system, follow the remaining steps in option 1 for changing the parameter name.
Thank you, mysterious David Benedeki who disappeared from StackOverflow after answer which helped enormously :)
As I can see the problem is more NetBeans-centric, so I would also suggest you to file a bug report to the NetBeans community.
The NetBeans forums.
The NetBeans bug tracker.
Maybe in the future they can fix that issue. You may also link that question so they can see the user reactions.
For module development with custom *BladeDataObject file
#MIMEResolver.Registration(
resource = "BladeResolver.xml",
displayName = "#LBL_Blade_LOADER"
)
and in the same package create the BladeResolver.xml file with the content
<MIME-resolver>
<file>
<ext name="php"/>
<name name="blade" substring="true">
<resolver mime="text/x-blade"/>
</name>
</file>
</MIME-resolver>

Zend Studio 8 PHP Core function not reconized (remote projects)

I'v recently upgraded from Zend Studio 7 to ZS 8 and i can not get ZS8 to reconize default PHP5 functions like explode(), split(), etc. It simply says "call to undefined function" and adds a yellow (warning) line under the call.
Google didn't provide me with any information that actually worked. The .buildpath looks fine:
<?xml version="1.0" encoding="UTF-8"?>
<buildpath>
<buildpathentry kind="src" path=""/>
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
</buildpath>
And the .projects file looks fine too:
<nature>org.eclipse.php.core.PHPNature</nature>
Now i'v noticed that when i start a new project LOCALLY it works fine and the "PHP language library" is added fine, but as soon as i open the 'remote systems' tab and right click on a folder and pick "Create remote project" The "PHP Language Library" is simply not filled. Which explains why it doesnt work.
Now the question is, why doesn't it fill up? How do i fix this? (without having to switch to another editor).
Try adding to .buildpath:
<buildpathentry kind="con" path="org.zend.php.framework.CONTAINER"/>
more: Built-In PHP Functions Are Not Recognized
I had the same problem with one of my projects and I followed the instructions here:
http://kb.zend.com/index.php?View=entry&EntryID=415
Although it's supposed to be for ZS7, they worked for my ZS8.
(It's essential to do the Project > Clean mentioned at the end).
I work with eclipe Indigo M5 package but I had the same problem. I fixed it uploading the content of the php plugin core on my remote server, and add it as external librairy folder.
The plugin is usualy located there : $HOME/workspace/.metadata/.plugins/org.eclipse.php.core
Hope this will help !
the easiest thing for me (regardless if it's a local or remote project) is to delete the project itself... but make sure you only delete the project and that the checkbox for 'delete contents' is NOT selected. then create a new project from an existing directory and continue where you left off. everything should work like a charm.
I know it's a really old question but I came across the same issue recently.
To fix it click with the right on the project and click on
properties->PHP->Interpreter
and enable the correct PHP version for the project
it solved the issue for me
ps. you can do the same at workspace level too

Why does Eclipse code completion not work on some projects?

I have Eclipse 3.3.2 with PDT doing PHP development.
All projects that I create, even SVN projects have code completion.
Now I just opened another SVN project and it has no code completion or PHP templates (CTRL-space does nothing in that project).
However, I can open the other projects and code completion all work in them.
Why would code completion and templates be "off" in just one project and how can I turn it back on?
Maybe Eclipse doesn't understand the project has a "PHP nature".
Try comparing the .project file on both projects to look for differences. It should contain something like:
<natures>
<nature>org.eclipse.php.core.PHPNature</nature>
</natures>
The .project file will be in your workspace under the project directories.
Look out for the file .buildpath in your project... put this line between the tag:
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
Save it and restart eclipse. Now everything should be OK... This worked for me. :)
Thank you!
I spent all day long to figure out why I did not have code completion...
The problem is that if you create a SVN project the .project is a basic file without codecompletion reference. You have to create a basic PHP project and compare the two files and replacing the missing part in the SVN project one.
Now I have code completion for every file in the project, even for Zend Framework library
It is just one line to add in the .project file and then restarting eclipse to get codecompletion:
Where it says
---
<natures>
</natures>
---
after the change has to be
---
<natures>
<nature>org.eclipse.php.core.PHPNature</nature>
</natures>
---
That should do.
#Guido PHPNature does not fix this.
#Edward Tanguay Yes, that's because when you create new PHP project, eclipse adds .buildpath file with
<?xml version="1.0" encoding="UTF-8"?><buildpath>
<buildpathentry kind="src" path=""/>
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/></buildpath>
when you import existing project you eclipse does not generates .buildpath file, but you can add it by hand or create new PHP project with existin source (you can choose in wizard).
I have the same issue sometimes. For me it works to rebuild the PHP project with "Project" -> "Clean".
If you have this problem, follow these steps :
Select "PHP Include Path" in your project tree
Right click on it then click "Build Path>Configure Build Path"
On the opening window,add folder that you want to build, so it can do code assist.
Thats all :) I hope it resolves your problem, I solved my one :)
Be sure the file opens with the "PHP editor". Right-click the file, and select open with to select the right editor.
If it turns out you've been using the wrong editor, you can change the association under Preferences » General » Content Types
Right click in the edit screen, goto Java -> Editor -> Content Assist -> Advanced ...select proposals accordingly
ATTENTION
Besides the already mentioned solutions to get the whole autocomplete help to work, there is another quirk: it might not be enabled.
Go to Window > Properties and then to PHP > Editor > Code Assist (JAVA has a similar option) and set "Enable auto activation", preferably with a delay that you see comfortable (0ms). If you are bothered by the program suddenly deciding to do things for you without prompt (and doing it wrong), deselect "Insert single proposals automatically" and you should be fine.
I've noticed sometimes when you checkout a project from svn in eclipse (subversive or subsclipe "checkout a project as") and even though you check it out as a php project it will either delete the .project file or it would be a generic project. I've found to just go in that directory and delete the .project .settings/ and .cach/
Then create a new php project and point the directory where you checked out the files. And you should have code completion and svn should be link to your repo.
I had a problem that build path was empty, so no code completion for any of the files i tried to edit. Make sure you setup properly your build path, especially if you're linking the source from some other location than the workspace.
Like the apache htdocs folder for example.
I have solved this by enabling the Full C/C++ indexer (Windows-> properties -> C/C++ -> Indexer), and also hit the radio button "Use active button configuration". After that Clean, and Build all.
That worked on Eclipse CDT 3.4
If you came here looking for code completion in php eclipse not working, make sure your project is being supported as a php project. Right click on the project and then go to configure -> Add php support. If you have the right settings for code assist it should work instantaneously. Sometimes newbies as me tweak around with the projects or start projects as clean and not as php so eclipse doesn't know how to treat the project.
I had to right click the project in the PHP Explorer, go to "PHP Build Path". This was empty. I clicked "Add Folder", selected the checkbox next to the root folder of my project and clicked "OK", then "OK" again.
After that code completion seemed to work. Should just work out of the box if you ask me, but whatever.
Check the lib of your project. It may be that you have include two such jar files in which same class is available or say one class in code can be refrenced in two jar files. In such case also eclipse stops assisting code as it is totally confused.
Better way to check this is go to the file where assist is not working and comment all imports there, than add imports one by one and check at each import if code-assist is working or not.You can easily find the class with duplicate refrences.
One solution could be to include a dummy php file wich requires all your PHP classes. So that the PHP parser recognizes these classes too.
Example dummy file:
if(false) {
require_once 'class/one.php';
require_once 'class/two.php';
require_once 'class/three.php';
}

Categories