What is the "Use Trait Body" setting for? - php

Recently I've started using PHP (worked for MS shops since graduating, and that was mostly what I used in college too). To help with this, I'm using Netbeans and am in the process of configuring it so that it's more similar to Visual Studio.
Under Options -> Editor -> Formatting, I've found this setting highlighted in the red box:
Any setting I pick for that value makes no difference in the sample file on the right. I copied the text from when I use the "Same Line" value and did a diff on it against the text when using "New Line" and they're identical.
So, what is this setting?
In the example to the right of the options, I thought this would impact the (new Example())->alignParamsExample(... and push anything after the -> onto a New Line, but that's not the case.
I've also read the documentation about traits but I'm still unclear exactly as to what the "trait body" would be. I typed out the code they provided in "Example #2 Precedence Order Example" but noticed no behavioral difference in the IDE.
I've tagged this question with both Netbeans and php tags; if I select other languages this option isn't present (but I only have HTML, JSON, Javascript, and PHP to chose from) so I wasn't sure if this is a "PHP thing" or a "Netbeans thing." If it's explicitly one or the other, let me know and I'll remove the tag.

I think this is about that block in class:
class ExampleClass
{
/** Start of Use Trait Body **/
use TraitOne;
use TraitTwo;
use TraitThree;
/** End of Use Trait Body **/
}

Related

Why won't the key combination Ctrl-K Ctrl-F work for php visual code?

I'm intending to format the selection (indentation) for the PHP code, but it does not work.
I already made sure that there aren't duplicate shortcuts.
I also disabled all extensions.
I changed the keyboard shortcut from Ctrl+K Ctrl+f to Ctrl+k Ctrl+y.
None of these helped.
Is the only language that does not work for me to format selection
Eye. It's not because I'm missing the closing tag (?>).
To see menu bar if not present press
Left Alt
then go:
Preferences > Keyboard Shortcuts
type in the search bar
ctrl+k ctrl+f
you should see
perhaps you have a collision and other command has the same shortcut defined or your shortcut is not defined at all.
You can double click on shortcut to edit it.
Note at the picture When this is when the command works because one shortcut may work only if you are currently editing document and other when you are browsing files so once you set a shortcut make sure your checking it in different places of editor to see if its working or not.
If you use shortcut:
Ctrl+Shift+P
and select command:
You'll see whole bunch of shortcuts and there should be there one you are missing:
{ "key": "ctrl+k ctrl+f", "command": "editor.action.formatSelection",
"when": "editorHasDocumentSelectionFormattingProvider && editorHasDocumentSelectionFormattingProvider && editorTextFocus && !editorReadonly" },
I think that you can just copy the one above, paste to your file if it is not present and save that file, restart your Code and all should be working. Remember that the file is JSON so keep its format - look how other keys are presented there and your pasting should not make JSON invalid.
.vue file doesn't have formate selection.
This function depends on your file type.
I checked that this key binding was indeed still specified, there was no duplicate key binding, etc.; still, Visual Studio Code refused to recognize the key combination. Then I quit visual studio code and restarted it, and the key combination started working again.
Sometimes, the basic quit-and-restart is the answer!
If nothing is working you can create your own "format selection" with multiple commands. You would need a code formatter and a macro extension to run multiple commands from one keybinding,I'm using "prettier" and "multi-command" extension.
You can use this keybinding in your keybindings.json (Click File -> Preferences -> Keyboard shortcuts. Use the tab that opens up to edit and find available key bindings) with the multi-command extension - no need for anything in settings.json:
{
"key": "Shift+Alt+A", // or whatever keybinding you wish
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"editor.action.formatDocument",
"editor.action.clipboardCopyAction",
"undo",
"editor.action.clipboardPasteAction",
]
},
"when": "editorHasDocumentFormattingProvider && editorTextFocus && !editorReadonly"
}
I use it because "format selection" is not working with "*.vue" files.

Visual Studio Code: how to prioritize one formatting provider over the other

I'm coding PHP and using a few extensions that are very useful:
PHP Formatter just for formatting code
PHP Intelephense for providing intellisense
In this case both of them are Formatting providers, so you can right click in your editor and select "Format document" and everything will get indented and beautiful.... you get the point.
The thing here is that the formatting done by the PHP Intelephense (which I don't like) is the one that stays.
If, for instance, I disable the Intelephense extension the formatting looks good.
Let me give you a visual difference between the two formatting:
Intelephense (bad):
if ($condition) {
doSomthing();
}
else {
doAnotherThing();
}
PHP formatter (good) [chek out the else]
if ($condition) {
doSomthing();
} else {
doAnotherThing();
}
Zanks in advance for your time
"intelephense.format.enable": false
This will do your work.
There is no generic way to choose one over the other. This is left to extension authors to handle via settings as explained in the docs here
What happens when there are multiple formatters for one language? This
can be a problem when different formatters' actions contradict. In the
October release, we added settings to enable or disable the default
formatters that ship with VS Code. The best practice is for extension
authors to add a similar setting as what we did in VS Code as shown
below.
"html.format.enable": true,
"javascript.format.enable": true,
"typescript.format.enable": true,
"json.format.enable": true
You can read more discussion on how they came to this in this github issue.
So what does this mean for you? It means that the intelliphense extension needs to add a setting to disable formatting. You can create an issue and wait for them to fix it or try to make a PR to fix it yourself.

CodeIntel with PHP in Sublime Text 2 not working

I am trying for 2 hours now to get SublimeCodeIntel working with PHP. Well, some things work, but CodeIntel doesnt autocomplete class methods and parameters when outside of the class.
I use Sublim Text 2 for Windows (7) and the last version of the plugin.
I have a class Page in classes/Page.php, and a index.php.
In index.php:
$page = new Page('home',$_GET['page']);
And when I type
$page->
I can read in taskbar "Info: processing 'PHP': Please Wait" for a few seconds and then nothing happens.
When working in Page.php, I can start typing $this->.. and it somewhat works (actually it doesnt show functions parameters).
Same with Alt+clicking on functions and variables (only works if they are defined in the current file)
I tried several things:
1/ Deactivating "detect_slow_plugins" (error message doesn't appear anymore, but the plugin is not working better)
2/ Changing SublimeCodeIntel.sublime-settings config (copy paste the whole file and editing values):
"codeintel_language_settings": {
"PHP": {
"php": "E:/wamp/bin/apache/Apache2.2.21/bin",
"codeintel_scan_extra_dir": [],
"codeintel_scan_files_in_project": true,
"codeintel_max_recursive_dir_depth": 15
}
}
I don't even know if the "php" value is important (I found several snippets on the internet)...
3/ Same thing in Sublim Text User settings
4/ Re-building indexes as advised here
I use an PHP autoloader and I don't get how the plugin knows for sure which file defines which class. Could be an issue ?
I am completely stuck here, I tried everything I found, and read some setup tutorials (each one of them being something like "install and it just works!"... very annoying).
Does anyone have a solution? Or something to check, or try...
Thanks!

PHP function descriptions as I type in Notepad++

Is there a plugin for Notepad++ which would allow me to see functions including parameters/returns as I type?
For example, if i type "implode(", I'd see:
string implode ( string $glue , array $pieces )
Update: Wow, I'm surprised so many other people were as interested in this as me. The take-home lesson for me was to always explore all the Settings options!
You don't need a plugin! 5.0 and above have this already.
Go to Settings -> Preferences, then go to the Backup/Auto-Completion tab, and you'll find it at the bottom! Check the box for function parameters hint as well.
You'll get exactly what you've asked for, as long as it knows the file is PHP.
maybe, plugin Auto completion for custom PHP classes (ACCPC) is what you're mean.
basic info:
Show an overview over your classes' attributes & methods in a nice popup!
A popup window appears after typing the "->" or "::" behind a class or an instantiated object variable which displays all attributes and methods of it's class.
more information:
http://sourceforge.net/projects/accpc/
maybe this answer can helpful too:
Get parameter hints from Editing the API XML file
https://stackoverflow.com/a/12609240/2427906
You can read about it in Notepad++'s documentation site found here
http://npp-community.tuxfamily.org/
The auto complete section can be found here
http://npp-community.tuxfamily.org/documentation/notepad-user-manual//editing/auto-completion

JavaScript: document properties

is there a "document" property named ssh? It's a simple question. I've seen this in some code at work, but no one in the office wrote the code, so I'm stucked.
The line was document.ssh.firstPing(...)
firstPing was a method in the code, that is writen in js+php. But I've searched with eclipse throughout all the code and there is no ssh anywhere.
There's no standard ssh property on the document object in the Javascript DOM bindings. If you're loading Javascript libraries, they could always add one (one can add properties to document if one likes). For instance, this is perfectly valid:
document.foo = {
bar: function() {
alert("Hi there!");
}
};
document.foo.bar(); // alerts "Hi there"
More on the standard bindings here.
ssh has to have been defined in some script somewhere. Since your codebase is partially PHP it may be a generated script and that's why it's not showing up obviously.
A technique you might try is open your page in FireFox with Firebug and analyze the list of scripts it shows to have loaded (under the scripts tab). The advantage here is that Firebug shows you eval scripts, not just the static script files. Firebug also lets you search through these. Then you may be able to backtrack from there into where it's being defined based on phrases.

Categories