Add php nature to project - php

I have a question about PHP projects in eclipse.
I have Aptana and PDT installed in my eclipse.
When I create PHP Project, I have something like this:
But if I add PHP nature to the project (org.eclipse.php.core.PHPNature) then I get following picture:
Is this normal at all? What are the benefits of this PHP nature?

This is absolutely normal and part of how PDT provides Code Assist in PHP projects.
Basically PHP Language Library contains what you can find in the PHP documentation. When you call a core function e.g. preg_replace() it will provide Code Assist, like autocompletion and showing you which arguments the function takes. It's just a bunch of Interfaces for core features, SPL containing phpdoc generated from the documentation.
The PHP Include Path resembles your include_path in PHP, in that you can refer to stuff outside your project, e.g. PEAR or a common folder containing shared PHP classes, which are then recognized by Eclipe's Code Assist.
is just a hierarchy view of your global namespace, similar to how you can unfold a php file and see its hierarchy directly from the explorer.

Related

How to configure Eclipse Project for Joomla Component Development

I like to develop a fresh Joomla Component for Joomla 3.x in Eclipse and created therefore a simple PHP project.
The problem I have is now how to setup the correct "include path", so that the basic Joomla PHP classes get found like "JFactory" , "JAccess", "JObject" ...
If I just include a Joomla installation in my include path, this will not work. I assume the paths to the classes are more sophisticated than that.
Any Idea or suggestion how the "include path" for my project should look like?
regards
Mark
It depends a little on what you mean by "found".
If you mean "as I start typing a basic class name every matching basic class gets offered as an option", yes, there is a way to do that.
See the conversation, and solution, on this gitHub page.
I have the stub file referred to and it works in the way I've said above, tho' I'm using NetBeans not Eclipse (but the reference to phpStorm makes me think it should/could work for you too), although I haven't been able to run the build script. I just haven't got the time to single step through it to find out where it stops.

How reuse custom code among projects using PHP natively?

I am not familiar with PHP and having a background in C#.
I would like to know if PHP offers a way to share custom code among projects natively in the language (targeting the latest version of PHP)?
As in C# there is the possibility to create a custom DLL, that can be included in other projects when needed in order to reuse some code.
Does PHP offer a similar feature?
Does PHP packages related on that?
Can PHP namespace be useful in this scenario?
What bout the use of include?
If PHP does not offer this support, which project/library can be used?
I understand there is the possibility to share common code from a versioning system such SVN and checkout sharedcode in each related project (as described in other answer on SO), but I am interested in the possibility in the language itself.
I think with phar archives and composer you get as close to assemblies and nuget as you can get.
You should try a php framework like Laravel or Zend Framework. If you don't want to try a framework, there are couple of ways.
You can create a class of functions and then you can include that class wherever you want in your scripts. This is a simplest example.
namespaces are your friends. I highly recommend yo to have a look at here for PHP and here for a PHP framework.
You can share code with composers packages, more on:
https://packagist.org/
https://getcomposer.org/

Add a custom PHP function to MAMP

I'm wondering what's the best way to extend the MAMP PHP core itself so that custom functions will be available globally without the need to import libraries.
A good example of what I want to do is to have a dd function (which is var_dump() + die(), inspired by Laravel) available in all my local projects.
These methods need to be available only on my local environement (where my version of MAMP is installed) and for debugging purposes only, so there is no fear of breaking PHP funcionality on end server.
Thanks for your help.
There are two approaches for this:
Adding a module to php which is loaded like all the other modules. Modules like database connectors, math libraries, translation functions, whatever. All those functions are not part of "the php core". The core implements only the language itself. You can see what modules are currently loaded and their configurations in your php setup by using the function phpinfo().
Implementing a module is possible, you need to know c or c++ langauge for this. An interesting project, you will learn a lot. But this is also a huge overhead to what you are looking for.
Implement your functions in a normal php file somewhere outside your normal project folder. Then register that file inside your http servers php configuration as "to be loaded for every executed script". That is exactly what the "auto_prepend_file" feature does. That way you can easily add global functions always available in all scripts on your local system.
Believe me, you want to give the second approach a try :-)
Without compiling your own extension to PHP, creating a global function that is automatically available to all scripts on the box without importing anything may be impossible.
You could create a file like "tools.php" that contains the dd function definition, and you do a call like require "tools.php" in your application. Put the development version of tools.php in a directory that is only available on the development server, in a path that is given highest priority in the include_path.
Then create a mirror tools.php in the codebase, with a lower priority in the include_path, that contains only stubs to your development methods. Therefore, on the dev box, the dev version of tools.php will be included. But on production, the production version of tools.php would be included.

Use PHPDocumentor to create an Eclipse Library

I have an unusual request,
I'm working on PHP 5.3, my IDE is Eclipse and I need help setting a file like the one that comes in default with the php functions, so I can use it for code completion and I can have the documentation on hover.
So basically, I have a library, which I want to pull the declarations for everything (function, classes, etc) and the PHPDoc block, and use them to create a new file, which will be added as a library on Eclipse on the include path. Anyone knows an automatic way to do it?
EDIT: To explain a bit better what I want to do. I want to run a script that will do almost what PHPDoc does, but instead of creating a set of html files after load a file, it will create a copy of the php file which only has the declarations and comments. So that file can be given to the programmers, instead of the full library with source-code.
I though about using the ReflecationClass, by including each file, check the defined class\functions and then writing the new file, but that means that all the includes\requires need to happen in order, something I can't guarantee
Not sure if this counts as "automatic", but what you describe sounds like it can be roughly accomplished by having this library itself as an open Eclipse project. If your "new code" is in a separate Eclipse project, then you want to list your library project in the new project's Include Path configuration.
In the "PHP Include Path" config popup for your new project, click "Add" and select the library project (it will only be visible here if it is also "open"). You can choose whether or not it should come before the new project on the include path or not by moving things around in the Order tab. I tend to keep my current project listed first, then dependencies afterward, just in case any of my new project's classes take precedence over same name classes in the dependency projects.
An added benefit to this is that when you open your new project, any referenced projects in the Include Path configuration will automatically be opened too.

Code completion for PHP extensions in Zend Studio?

After having installed the HTTP extension from PECL, I expected Zend Studio 6 to recognize the provided HTTP* classes and for code completion to be made available. This is not the case, however. How do I get Zend Studio to recognize classes provided by PHP extensions? Specifcally, I want to be able to use code competition on these classes.
I used the phpgenerator.php script from Michael Spector. It generates a php documentation folder with the loaded extensions on your pc. Afterwards the doc path can be added to the Eclipse (Zend Studio) include path. Code Completion works like a charm.
usage:
console: php phpgenerator.php $path_to_doc_output
http://dev.eclipse.org/viewcvs/viewvc.cgi/org.eclipse.pdt/plugins/org.eclipse.php.core/Resources/language/?root=Tools_Project
This script can be used for generating PHP model for PDT.
It builds PHP functions according to the loaded extensions in running PHP,
using complementary information gathered from PHP.net documentation
*
#author Michael Spector
In Eclipse, with which Zend Studio shares code, so it might help, is the "PHP Include Path".
"PHP Include Path" is in the project explorer.
There you can add the directory where the extensions are. Then Eclipse will scan it and you will be able to code-complete.
I did the same with PhpUnit2.
I'm not familiar with Eclipse, but if it works in the same way as Netbeans handles PHP extensions, you'll need to add the relevant stub PHP files to the IDE's search path.
You can add functions to Studio by putting PHP files with stub function descriptions into special directory. Find this directory in filesystem in a following way: write something like gmdate(), select the name and press F3. You will be taken to one of the prototype files. Note the directory where this file resides (shown on the top and if you hover over the tab). Now you need to create stubs for functions you are missing just like the one you're looking at. You can put them into any file, generally, but I suggest putting them into separate file - like geoip.php - and put this file into that directory. You may also want to do right-click/Show In/PHP Explorer and browse other prototype files if you need examples of how to do it right.
Zend ship language support for all the extensions in Zend Studio.
The most efficient way of adding support for language entities provided by unsupported extensions is definitely creating stubs (You can add this support yourself). The description "stub" files for all supported PHP entities can be found in this directory:
/.metadata/.plugins/org.eclipse.php.core/language
(this is also the location where you should put your stub files).

Categories