I use the IDE Visual Studio Code to write scripts in PHP. To write plugins in PHP for a store system, I need to add an external library to my worktree. I have already cloned the library from github and added the folder to my workspace where I am working on the plugin.
The problem is that my IDE still gives errors that namespaces and classes can't be loaded because, for example, there is no namespace with that name. I also can't use the autocomplete feature.
Can someone explain me how to fix this problem?
Screenshots:
Undefined Type [...]
I have solved this problem now! To fix this problem I needed the vscode plugin "Intelephense".
In VSCODE: right click on the folder where the interface must be used and click on "Folder Settings". In the second row under the intelephense extension the radio button "Intelephense > Environment: Include Paths" is shown. There I had to add the path to the interface.
Related
I'm switching from PhpStorm to VSCode for my PHP development and I have a problem: For my multi-root workspace, it only detects the classes from the current repository, not all the other repos and libraries from my project. For example, when trying to autocomplete a class, Go to Definition, etc.
I'm developing a TYPO3 project, using composer. Therefore, the structure of the nested projects is this one:
path-to-html/
path-to-html/public/typo3conf/ext/{extension1, extension2, etc.}
I've installed the VSCode PHP Intelephense extension and configured it according to its description. But, as I've said, I only get completion for symbols of the current repository, not of all the libraries of the TYPO3 project. How should I configure this?
I've read all the Intelephense options and I've tried setting these ones:
"settings": {
...
"intelephense.environment.documentRoot": "/path-to-html",
"intelephense.environment.includePaths": [
"/path-to-html/public/typo3conf/ext/extension_1",
...
]
}
But it still doesn't work.
Disclaimer: I also have "PHP Intellisense" installed. The context menu items such as "Go to Defintion" or "Go to declaration" etc only work correctly, when I use enable both extension. Maybe it has to do with the fact that "PHP Intellisense" also uses the Language Server Protocol, but the implementation of the LSP is provided by "PHP Intelephense". Admittedly I don't understand it fully, .
In any case, these "PHP Intelephense settings" work for me.
I am using these settings right now for a local TYPO3 CMS 10 version, ddev-based.
I'll provide it here as a screenshot because these are VSCode Workspace Settings, and I cannot fgure out where VSCode stores these. (They are not stored in the $HOME/.config/Code/Usersettings.json file).
I think I could have used $HOME/ddev/typo3-10/public/typo3/sysext/ instead of $HOME/ddev/typo3-10/public/typo3/. Havent't tries
Key is,
Intelephense needed a few minutes to pick up the settings after changing them. It does not happen instantly that the red wiggly lines disappear
Needless to say, "Go to Definition" (opens a Doc-preview Window), "Go to Declaration" (Opens the PHP Class File), etc, are only enabled for Intelephense Premium.
No need to install, while it is supposed to be there and the html is useless.
The config needs to include the sources; eg.:
"intelephense.environment.includePaths": [
"../../typo3_src/typo3_src-8.7.44"
]
Also see: https://github.com/bmewburn/vscode-intelephense/issues
I just quit VS Code and re-open it. VS Code will open in the exact state it was in on quit. And Intelephense will have scanned the vendor folder. No need for any config changes.
While trying out the VSCode on my PHP projects, I couldn't find an option/setting/extension that would allow me to add an external library and show any autocomplete tips based on the included code.
This feature is present in PHPStorm out of the box.
Am I missing something or VSCode really doesn't support this yet?
To add an external dependency you can use the VSCode multiroot workspace feature.
The File > Add Folder to Workspace... command brings up an Open Folder
dialog to select the new folder.
https://code.visualstudio.com/docs/editor/multi-root-workspaces#_adding-folders
I have created a web page in NetBeans with Html 5 and CSS, and now I want to add a PHP file in that project, but there is no option to add a php file.
I added empty file (xxxxx.file) and renamed it xxxxx.php and added the php code there, but it doesn't recognize it as php code. It sees the file as php file.
What should I do? Should I create new PHP project and copy the html and css files from my old project to the php project to get them working all together?
You can have php files in HTML5 projects. If you are not seeing the syntax highlighting for the code make sure that your php files have the opening php tag:
<?php
Without this the exitor will not highlight it correctly
if PHP's aren't being recognised you should install the PHP plugin for Netbeans. You should go to Tools > Plugins > Available Plugins and select the ones for PHP in the list. Then, restart the IDE.
It seems there is a Netbeans bug which makes you impossible to add php files to html5 projects. The answer, as given by Netbeans people, is to create a new php project and add the html5 files there.
Here you can see the bug report on netbeans forum: https://netbeans.org/bugzilla/show_bug.cgi?id=226280
I wanted to start a new Zend project, and currently I'm facing some issues regarding Eclipse PDT... My problem is, that the code completion in Eclipse for PHP does not work at all.
I tried a lot of different tutorials etc, for example making a new project and import the files; making a new workspace and import projects there; almost every possible combination of buildpath settings and library imports; deleting several files in .metadata (you will find lots of tutorials like this if you google for it), but nothing worked.
[Edit] Also the PHPNature is set (thanks to tranisstor):
<natures>
<nature>org.eclipse.php.core.PHPNature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
(It also does not work if there is only the PHPNature set, and no other in addition)
[/Edit]
The problem in detail: I made a new Zend project, and tried to start coding in the IndexController.indexAction(). First thing I did: I typed in $this->, but no code completion came... I thought maybe I would need to add the Zend library, which I did. When I click into the Zend_Controller_Action in class IndexController extends Zend_Controller_Action I can see the documentation of Zend_Controller_Action, I also can press F3 and the corrosponding file will appear... Which means, Zend is successfully added as library.
I also tried Ctrl + Space, but just nothing happens. By the way, the standard PHP functions like isset() also won't show up in code completion
Does anybody have a idea how to fix this? I am using Eclipse Juno, with Eclipse PDT 3, and Zend Framework 1.x (don't know exactly, but it's not ZF2 and it works well if I open http://localhost.
I'm grateful for any help
I had the same problem when upgrading eclipse to Kepler. The following worked for me:
Remove files under workspace/.metadata/.plugins/org.eclipse.dltk.core.index.sql.h2
The reason was that the workspace old DLTK index is not compliant with the new version and needs to be rebuilt. Start eclipse and the DLTK index will be regenerated.
Code completion worked for me again after that.
i feel you, i had to deal with this quite often too, and the mentioned .project file modifications didn't do the trick.
What helped me was this:
edit the .buildpath file and add
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
My complete build file might then look sth. like this:
<?xml version="1.0" encoding="UTF-8"?>
<buildpath>
<buildpathentry kind="src" path=""/>
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
</buildpath>
i also added my folder which contains the php files to the build and include path (RMB over the project), but i don't think that it was necessary, the most important part was the modification of the .buildpath file for me.
Hope that helps...
The standard solution (at Eclipse forum) didn't work for me. What fixed this problem was the following:
going to Properties for my project (right click on it in PHP Explorer, then Properties),
select PHP Build Path/"Add Folder"
in there I ticked/selected my project's main folder.
It took a while while the DLTK database was refreshed (it could block your machine for a couple of minutes, be patient) but then it started working great.
Remove workspace/.metadata/.plugins/org.eclipse.dltk.core.index.sql.h2/*. It should works.
Hope it helps!
I think this is the best way:
Right click on you project in the project Explorer » Configure » Add PHP support...
Maybe you need to edit your .project-File and add a "PHP nature" tag. See this thread for more information. I once had this issue after putting a project under svn version control and it seems to be a common problem.
I've found a sollution on eclipse forum. Downgrading to PDT 3.1.2 solved the problem.
Regards,
Marek
I had a similar issue, but involving just one PHP file. Then I found that I was using the following syntax for the initialization of a variable inside a method:
$rule = ($fullValidation)?(new StartTimeRule()):(new NullRule());
The problem seems to be the use of the inline condition. The code was working but apparently broke some Eclipse features, like the F3 command, autocompletion, the outline view, etc. I could be wrong, but I think this is a bug of the DTLK indexer.
I changed that line with a standard if statement, not an inline condition, and all the features now work again.
Hope this can help!
After trying the other possible solutions on this page, I managed to get code completion to work in PDT 3.2 with the latest Dynamic Languages Toolkit in Eclipse Juno.
Juno usually installs DLTK version 4.0 by default so I downloaded DLTK 5.0 from here: http://download.eclipse.org/technology/dltk/downloads/drops/R5.0/R-5.0-201306060709/. Use the Core Frameworks > EMF > Runtime Version link, which downloads a zip file so you will need to do a local install:
In Eclipse select Help > Install New Software > Add > Archive > navigate to the zip file > type DLTK in the Name box and confirm.
Use Eclipse's Install new software to get PDT 3.2 from the PDT repository, if it is not already installed: http://download.eclipse.org/tools/pdt/updates/3.2/release
Option 2: Before I tried the previous method I installed PDT 3.1, which I got from the Juno update site (instead of the PDT repository):
Install New Software > http://download.eclipse.org/releases/juno. Code completion worked in 3.1, so it's another possibility.
Download ZF2 and put it to your perefered Location (~Frameworks/ZF2)
Eclipse: Window > Preferences > PHP > Libraries = Push "New"-Button, add a Name
choose added Item and click "Add External Folder"-Button. Choose you ZF2 destination
Be sure, your Project is "PHP Project" (see: Mark Project-Base-Folder, click Project in Menu > Project Natures and choose PHP Project.
This will rebuild your Project, if not also choose Project > build Project.
Now all should work like a charm (on Kepler Service Release 2)
I created one class file in eclipse IDE. However, Eclipse does not include that file in the searching list when I press Ctrl + T for searching a type. I don't know why this happens. Has anyone met this problem before? What's the solution? Thanks for help.
P/S: I'm using PDT plugin for Eclipse
Eclipse autocomplete function also didn't work, when I press Ctrl + , there's no autocomplete list.
Here are a few things you can try:
Make sure the file is in a source folder in a Java project. If you just create an arbitrary .java file somewhere, it doesn't necessarily get compiled (and added to the list of types for the type browser) - it has to be on the build path of a Java project.
If 'Build Automatically' is not turned on, have you built the project?
Occasionally, projects can get in a weird state. Try cleaning the project (Project > Clean...).
I can solve the problem by myself. I inspected the log file of Eclipse and see that there're some problem with the workspace. I deleted the workspace and created new workspace with old project. The problem disappeared.