How To Add PHP Library To Netbeans? - php

I am creating a PHP library of the functions and snippets I use most.
I am trying to set the library project up so that I can use it across other projects.
Currently I have it in the global include folder and the autocomplete for my functions is working well.
However when I run the functions I receive an error because they are not included how do I go about finding them to include them. Or is there a way for me to auto copy them into the source folder of the second project.

Add path to your library into include_path in your php.ini

Related

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.

Add php nature to project

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.

Why Zend Framework has to be configured through include_path

Why do I have to configure an include_path when installing Zend Framework instead of just manually including? I've never done this before and can't really see the point, also I've spent some time trying to figure this out with no luck hence why I ask.
Actually I add Zend framework to the include path to be able to use Zend tool.
If you want to create a project structure and add controllers or models or even scripts using Zend Tool you will have to have Zend framework added to your include path.
Another reason you may want to ship your project without the library itself so that the end user doesn't update the framework version himself and break your code.
Also if you are working on different project at a time you may want to keep only one version of the framework shared between different projects. This is handy when you need to update your version of the framework without going through all projects every time.
You don't have to set your php include_path to include the ZF library you could just copy the whole ZEND directory into your applications Library directory and continue on.
But a lot of us are working on more then one project or don't want to have the library in our application so we add it to the php include_path so php and our application can find it.
Now if you are refering to the windows or linux path, those are required to use the ZF cli components ZF.bat and ZF.sh
When modifying the Include Path you can use Zend Framework without knowing the Full-Path of it. You can simply use require('Zend/Loader/Autoloader.php') and PHP will search in every include path.
For more information have a look at: http://php.net/manual/en/ini.core.php#ini.include-path

Inside Eclipse PDT whats the purpose of "PHP include path" in project properties?

Was wondering when we right click on project folder in php explorer then there is an option "Php include path" it does not edit include_path property of php.ini . Hence even specifying include path using this option it does no different to project then whats its purpose of it??
Its is used to link two projects together within eclipse. If one project includes code from another project, eclipse is not aware of the connection and only evaluates the code with the project you are in. So if you try and use a function from another project for example, there would be no auto complete etc for that function.
By adding the second project to your include_path you are telling eclipse that you are using that project and all that projects classes, functions etc will be added to the auto complete and documentation prompt.
You are still required to connect the two by code.
The webserver (more accurate: The interpreter process created by the webserver) cannot know, that you even use an IDE to write your scripts, so its also impossible for it to know the project settings. If you execute it from within eclipse, it provides a custom php.ini, that contains the given include-path.

Categories